Jump to content

PHP Checkbox Value of "On" or "Off"


dlebowski

Recommended Posts

I have been struggling with this for days now and finally decided I needed to ask for help.  I am wanting to submit a value to my database of either "On" or "Off" from the checkbox.  I don't understand why regardless of whether the user has the box checked or not, it always submits "On" in this case.  Can anyone help me with this?  I want the checkbox to submit "Off" if the box is unchecked and "On" if the box is checked.  I would also be able to work with this checkbox if it submitted nothing when it was unchecked or "On" if it was checked.  Any guidance would be appreciated.  Thanks!

 

<html>
    <head><script language="JavaScript" src="test.js"></script></head>
<form>
<tr>
<TD width=68 height="29" align="center"><input type="checkbox" name="ud_test" <? if($test == "on"){echo "CHECKED";}?>></td>         
<td><input value ="DEL" type="Button" onclick="test(ud_test.value)"></td>
</form>
</html>

Link to comment
https://forums.phpfreaks.com/topic/53055-php-checkbox-value-of-on-or-off/
Share on other sites

lol... i wish!

 

problem with checkboxes, is that if checked, they transmit on(or whatever you put for value=""), if their not checked, they dont transmit anything.

 

so if checked, post=array(checkbox=>"on"), if not checked, post=array()... so you'd need to set a loop, to unset() all the ones, that arnt checked

taith, thanks for the quick reply.  For some reason, when I click submit with the box unchecked, it still submits "on"!  It sounds like it should be submitting a blank.  Is that correct?  I could deal with that with what I want to do.  I can't even get it to submit a blank when it isn't checked!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.