Click to See Complete Forum and Search --> : Help with Checkbox!


Stagetenor
08-16-2006, 04:17 PM
Hi -

I am trying to create an online registration form, and I am having the following problem.

I have it so that when a checkbox is check, a text box reads "0" (the initial value of the box is "20"). When the checkbox is unchecked, I need the value to return to "20" - right now it is not doing that.

Here is the code...

<input name="RCMExaminerChk" type="checkbox" id="checkbox" onclick="if (this.checked) form.textbox.value=&quot;0&quot;" value="true" />

What do I add to this to get the "uncheck" to work?

Thanks!

ahk2chan
08-16-2006, 05:24 PM
Here is the code that I have tested with.

<form name="testform" action="/test.asp" method="post">
<input type="checkbox" onClick="if (this.checked) { document.testform.textbox.value='0'; } else { document.testform.textbox.value='20';}" name="testcheck"/>
<input type="text" name="textbox" value="20"/>
</form>

Stagetenor
08-16-2006, 06:49 PM
WONDERFUL! It works. I had to do a little editing of it because I am using Dreamweaver, which likes to have things a specific way.

Here is the code I ended up using, in case anyone else ever needs it:

<form id="form1" name="form1" method="post" action="">
<label>
<input name="checkbox" type="checkbox" id="checkbox" onClick="if (this.checked) { form.textfield.value=0; } else { form.textfield.value='20';}" value="checkbox" />
</label>
<label>
<input name="textfield" type="text" id="textfield" value="20" />
</label>
</form>
:D