www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help with Checkbox!

  1. #1
    Join Date
    Aug 2006
    Posts
    9

    Question Help with Checkbox!

    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!

  2. #2
    Join Date
    Aug 2006
    Location
    Toronto
    Posts
    104
    Here is the code that I have tested with.
    Code:
    <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>

  3. #3
    Join Date
    Aug 2006
    Posts
    9

    Talking Thank you

    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>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles