|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is it possible to put a value for non-checked checkboxes?
|
|
#2
|
|||
|
|||
|
Example:
<FORM METHOD="POST" ACTION=""> What color?<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="red" CHECKED> Red<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="white"> White<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="blue"> Blue<BR> <INPUT TYPE="submit" VALUE="Submit"><BR> </FORM> Note the "CHECKED" for the color Red |
|
#3
|
|||
|
|||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Vernon Frazee:
Example: <FORM METHOD="POST" ACTION=""> What color?<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="red" CHECKED> Red<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="white"> White<BR> <INPUT TYPE="checkbox" NAME="color" VALUE="blue"> Blue<BR> <INPUT TYPE="submit" VALUE="Submit"><BR> </FORM> Note the "CHECKED" for the color Red[/quote] What I meant was, is it possible to place a different value than '' which a non-checked box sends. |
|
#4
|
|||
|
|||
|
Since there are three options above, and any or all can be checked,
there are nine possible combinations (3^3): 1) If Red is checked, you'd receive: color=red 2) If White is checked, you'd receive: color=white 3) If Blue is checked, you'd receive: color=blue 4) If Red and White are checked: color=red&color=white 5) If Red and Blue are checked: color=red&color=blue 6) If White and Blue are checked: color=white&color=blue 7) If White and Red are checked: color=white&color=red 8) If Red, White and Blue are checked: color=white&color=red&color=blue 9) If nothing is checked: (not even the "color=" portion would be sent) If you *must* receive a line beginning with "color=", insert <INPUT TYPE="hidden" NAME="color" VALUE="_"> right under the <FORM tag. Of course you'd then have a color=_ pre-pended to any other "color=" values sent too. If you *must* only have a "red" or a "white" or a "blue" value for "color=" use the "radio" option instead of "checkbox". |
|
#5
|
|||
|
|||
|
I'm not sure if this is what you're asking or not, but according to Microsoft (via the W3c standard) in IE there's no way to have the unchecked check boxes be transmitted via post operation and therefore show in the Request collection on the form action page.
|
|
#6
|
|||
|
|||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by matthewbward:
I'm not sure if this is what you're asking or not, but according to Microsoft (via the W3c standard) in IE there's no way to have the unchecked check boxes be transmitted via post operation and therefore show in the Request collection on the form action page.[/quote] This was exactly what I was wondering, thanks.. |
|
#7
|
|||
|
|||
|
Yes, you CAN return a value for a non-checked checkbox. This requires javascript but it works great.
The trick is to use a hidden field to store the values of your checkbox and use a javascript to toggle it for you. Since hidden fields always get their value returned in the request object this overcomes the problem with checkboxes getting turned off not firing a "change event". For every check box there is an associated hidden field. For example, say a database item is flagged as active, its associated checkbox will show as checked. Note its name contains an embedded dollar sign ($). Note the javascript "onClick" event that we'll use to toggle the value of our hidden field. <INPUT TYPE="checkbox" NAME="feature_active$S0F1" onClick="toggleCheckValue(this);" VALUE="on" CHECKED > Its associated hidden field has the exact same name except the dollar sign ($) is replaced by an asterisk. Note its value is "1" indicating that it is active. <INPUT TYPE=hidden NAME="feature_active*S0F1" value="1"> Now, with javascript you can toggle the value that gets called for the "onClick" event: <script language=javascript> function toggleCheckValue(objCheck) { var strCheckValName = objCheck.name; //get the name of the checkbox, e.g. feature_active$S0F1 var intPos = strCheckValName.indexOf("$"); //find the dollar sign's ($) position in the string var strWhichCheck = strCheckValName.substring(0, intPos); //grab the first part of the name, e.g. feature_active // build the name of the matching hidden data field, e.g. feature_active*S0F1 strCheckValName = strWhichCheck + "*" + strCheckValName.substring(intPos + 1, strCheckValName.length) ; var objForm = objCheck.form; // toggle the matching hidden field's value objForm[strCheckValName].value = objForm[strCheckValName].value ^ 1; } </script> Best Regards, Bo Gulledge Brainbuzz.com, Inc. bo@brainbuzz.com [This message has been edited by trackerbo (edited March 14, 2000).] [This message has been edited by trackerbo (edited March 14, 2000).] [This message has been edited by trackerbo (edited March 15, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Possible to put a value for non-checked checkboxes? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|