#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    6
    Rep Power
    0
    Is it possible to put a value for non-checked checkboxes?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    25
    Rep Power
    0
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    6
    Rep Power
    0
    <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.

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    25
    Rep Power
    0
    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:
    &nbsp; &nbsp; (not even the "color=" portion would be sent)

    If you *must* receive a line beginning with "color=", insert
    &nbsp; &nbsp; <INPUT TYPE="hidden" NAME="color" VALUE="_">
    right under the <FORM tag. Of course you'd then have a
    &nbsp; &nbsp; 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".
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Atlanta, GA USA
    Posts
    2
    Rep Power
    0
    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.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    6
    Rep Power
    0
    <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..

  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    1
    Rep Power
    0
    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).]

Similar Threads

  1. Checking checkboxes
    By missfmp in forum Java Help
    Replies: 4
    Last Post: July 6th, 2003, 07:44 AM
  2. Making the Check box value checked
    By Som in forum PHP Development
    Replies: 10
    Last Post: March 17th, 2003, 11:06 PM
  3. Replies: 4
    Last Post: June 5th, 2001, 02:21 PM
  4. Making sure 2 different checkboxes are checked
    By mstembri in forum HTML Programming
    Replies: 2
    Last Post: February 6th, 2001, 12:26 PM
  5. php and html form checkboxes
    By tigg in forum PHP Development
    Replies: 4
    Last Post: August 2nd, 2000, 05:04 AM

IMN logo majestic logo threadwatch logo seochat tools logo