Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

changing a hidden field value from a checkbox

Javascript coding ..

Moderators: macek, egami, gesf

changing a hidden field value from a checkbox

Postby spartan7 » Wed Jul 05, 2006 1:11 pm

I have a checkbox and hidden field within a form :

Code: Select all
<input name="checkbox1" id="checkbox1" type="checkbox" value="abc" onClick="document.forms[0].hidden1.value = '1'>

<input name="hidden1" id="hidden1" type="hidden" value="0">


So, basically I'm changing the value of the hidden form from the checkbox onClick...Which is fine...But I also want when you click the checkbox again (to untick it) the hidden field reverts back to it's old value.

So I want if you click the checkbox first to tick it, the hidden1 value is put to 1. Then if you click that same checkbox again to untick it, I want the hidden1 value changed back to 0.

How do I do it?

Thanks
spartan7
New php-forum User
New php-forum User
 
Posts: 17
Joined: Sat Jun 18, 2005 9:08 pm

Postby Redcircle » Fri Jul 07, 2006 3:30 pm

make a function that checks the value.

Code: Select all
<script type="text/javascript">
checkHidden(hidden){
if(document.getElementById(hidden).value == 1){
  document.getElementById(hidden).value =2;
} else {
  document.getElementById(hidden).value = 1;
}

</script>

<input name="checkbox1" id="checkbox1" type="checkbox" value="abc" onClick="checkHidden('hidden1');>
<input name="hidden1" id="hidden1" type="hidden" value="0">



somthing like that.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.