-
September 1st, 2006, 07:56 PM
#1
[RESOLVED] Forms and PHP
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?
-
September 1st, 2006, 08:43 PM
#2
Re: Forms and PHP
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
A few friendly reminders: * Use Code Tags when posting code.
* Rate good replies/post by clicking "Rate this Post" and leaving a positive feedback. * Things should be made as simple as possible, but not any simpler. -- Albert Einstein
-
September 1st, 2006, 08:55 PM
#3
Re: Forms and PHP
Ok i'll try to elaborate a bit more.
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>
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'.
-
September 1st, 2006, 09:49 PM
#4
Re: Forms and PHP
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)">
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 1st, 2006, 10:09 PM
#5
Re: Forms and PHP
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.
Last edited by cherish; September 18th, 2006 at 10:34 PM.
A few friendly reminders: * Use Code Tags when posting code.
* Rate good replies/post by clicking "Rate this Post" and leaving a positive feedback. * Things should be made as simple as possible, but not any simpler. -- Albert Einstein
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|