Forms - Populating a check box with info from a database
Below is an example of populating a
check box for use with a Boolean (Yes/No) field in your database.
This is just an example.. when doing this for real you would
do a query to determine the existing values for all the form fields... for this example we
will populate the variable ourselves with either a "True" or "False"
value. If the value passed to the save page is not "True" then it is
"False" and therefore you update the database accordingly.
<%
FRONTPAGE_ACCESS = "True"
%>
<form method="POST"
action="somepage.asp">
<div align="center"><center><table border="0">
<tr>
<td>FRONTPAGE_ACCESS</td>
<td><input type="checkbox" name="FRONTPAGE_ACCESS"
value="True"
<% If FRONTPAGE_ACCESS =
"True" Then Response.Write (" checked") %>></td>
</tr>
</table>
</center></div>
</form>
And this is what the output would
look like if the boolean field was "True".
Below is an example of populating a
check box for use with a text field in your database where you have manually inserted text
like"Yes" or "No".
This is just an example.. when doing this for real you would
do a query to determine the existing values for all the form fields... for this example we
will populate the variable ourselves with eithor a "Yes" or "No"
value. On the save page if the field passed doesn't = "Yes" then it is the
opposite so in this case you assign the database the "No" value on the save page
<%
CGI_ACCESS = "No"
%>
<form method="POST"
action="somepage.asp">
<div align="center"><center><table border="0">
<tr>
<td>CGI_ACCESS</td>
<td><input type="checkbox" name="CGI_ACCESS"
value="Yes"
<% If CGI_ACCESS = "Yes"
Then Response.Write (" checked") %>></td>
</tr>
</table>
</center></div>
</form>
And this is what the output would
look like if the text field has the text "No" in it
|