Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes..

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
Im trying to figure out the best way to get this done. I have two checkboxes. I need them updated to the db if they are checked or uncheck. This is the direction I am going im sill not sure whats the best way to get it to update.

check values = [id number]

Code:
If Request.QueryString("mode") = "update" then
message = "Account updated!"

If NOT Request.Form("check1") = "" then
message = "Check1 - updated"
Sql = "UPDATE users SET check1 =" & [??] & "WHERE user_id =" Request.Form("check1")
End if

If NOT Request.Form("locked") = "" then
message = "Check2 - updated"
Sql = "UPDATE users SET check2 =" & [??] & "WHERE user_id =" Request.Form("check2")
End if

End If
I guess the real question is...how do I put the value if the check box is checked or not..do I just send "True" or "False" and also is this a good way to do this?


 
Hi

What database are you populating? An Access db requires -1 and 0 to represent true and false respectively, whereas others use true and false, 1 and 0 etc.

Whenever I can't be bothered to mess with checkboxes (and the validation code to go with it) I convert them into two radio buttons, which I can give two separate values, such as "-1" and "0". When the user submits the form I just use the value of the request variable to populate the database. That way the value is always set one way or the other without validation and odbc errors.

Sorry - did I ramble then? Well it is late here ...
Derren
[The only person in the world to like Word]
 
You could use the radio button solution, which may or may not work depending on your application. Just the fact that you've decided to use checkboxes indicate a possible need for it (gee, that was deep ;-) )

What I will normally do is set the value of any checkbox to "1", so:

<input type=checkbox name=check1 value=1>

then you just check:

if request.form(&quot;check1&quot;) = &quot;1&quot; then
'it was checked
else
'it wasn't checked
end if

You can also give the two checkboxes the same name, and receive a comma separated list:

<input type=checkbox name=check1 value=0>
<input type=checkbox name=check1 value=1>

then, when you:

request.form(&quot;check1&quot;)

you'll either get:
&quot;&quot;,
&quot;0&quot;,
&quot;1&quot;, or
&quot;0,1&quot;

which you can use as you see fit, much like the multiple select list, so:

dim check1
check1 = request.form(&quot;check1&quot;)
if instr(check1,&quot;0&quot;) > 0 then
'they checked the 0 value one
end if
if instr(check1,&quot;1&quot;) > 0 then
'they checked the 1 value one
end if

either way.

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top