Ok this is going to sound real newbish probably but here it goes anyway. I know how to set a value for when a box becomes checked. But How do you set a value for when it's becomes unchecked?
Printable View
Ok this is going to sound real newbish probably but here it goes anyway. I know how to set a value for when a box becomes checked. But How do you set a value for when it's becomes unchecked?
Your question is a little bit confusing. :) But here are some links about checkboxes. Hope these helps:
http://www.webdevelopersnotes.com/ti..._checkbox.php3
http://www.quirksmode.org/js/forms.html#scheckbox
Regards
Ok i'll try to elaborate a bit more.
As shown here if $myrow3=$myrow the box will be checked. The corresponding value to the check mark is if the box is checked. so if the user leave the box checked nothing will happen. what if he unchecks the box? How do you set value for unchecked to '0'.PHP Code:<tr>
<td width="334">IP 2</td>
<td width="455"><?php echo $myrow['IP2'];?></td>
<td width="24"><input type="checkbox" name="IP2" value="1"<?php
$sql3="SELECT * FROM blocked WHERE IP='". $myrow['IP2']."'";
$result3=mysql_query($sql3);
$myrow3=mysql_fetch_array($result3);
if ($myrow3['IP']===$myrow['IP2']){echo " checked";}?>></td>
</tr>
This is also client-side scripting. You have to give the checkbox an id and use getElementById().
I threw in some other code that might be useful later.
Code:<script language="JavaScript">
function setCheckbox(id, bool){
if(bool == true){document.getElementById(id).checked = true;}
if(bool == false){document.getElementById(id).checked = false;}
}
</script>
<input type="checkbox" id="chk1" checked>
<input type="button" value="Uncheck" onclick="setCheckbox('chk1',false)">
I wonder, why do you want to change the value of the checkbox to 0? Is it to see/find out whether that checkbox has been checked or not? If so, then there's no need really, for checkboxes returns the value (in this case "1") IF it is checked, otherwise it won't return anything (null). So, when you submit the form, and you do a if(isset($_POST["IP2"])) {...} (meaning: IF checkbox named "IP2" is checked) this will return TRUE, otherwise FALSE. If TRUE, you can then check if the value of $_POST["IP2"] is equal to 1 or not.
But if it's important you change the value to "0" you can do it with Javascript. Use OnClick="javascript_here" in your checkbox, and have your javascript change the value. The second link I posted earlier shows this. :)
// Oops. I didn't see you posted already, Paul. :wave: