Solved

Auto Check a checkbox when user begins typing in textbox

Posted on 2003-11-18
5
363 Views
Last Modified: 2006-11-17
I have a checkbox sitting next to a textbox.  The checkbox tells the form that there is valid information in the textbox.

What I need is if the user begins typing in the textbox without checking the checkbox, the checkbox should automatically become checked.

Sounds easy, but form field manipulation syntax confuses me.

Also, does anyone know of a website where I can learn more about javascript manipulation of form fields?

Thanks in advance.
0
Comment
Question by:ddotson
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Bustarooms earned 50 total points
ID: 9773122
<input type="textbox" name="myTextbox" onkeyup="this.form.theCheckbox.checked=(this.value != '')?true:false;"><br>
<input type="checkbox" name="theCheckbox">
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9773267
you could do without the checkboxes and just do some client siode javascript form validation
0
 

Author Comment

by:ddotson
ID: 9773548
That's true; however, the checkboxes are in use elsewhere in the form, and it is sort of a visual cue more than anything.

I tried Bustaroom's code, but it didn't work.  Here is what I have:

<input type = 'checkbox' name = 'otherEmail' value = 'yes'>
Other: <input type = 'text' name = 'otherEmailText' size = '35' onkeyup='this.form.otherEmail.checked=(this.value != '')?true:false;'>

BTW I am using it in ASP, hence the single quotes.
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9773563
then you will need double quotes in the js part

<input type = 'text' name = 'otherEmailText' size = '35' onkeyup='this.form.otherEmail.checked=(this.value != "")?true:false;'>
0
 

Author Comment

by:ddotson
ID: 9773707
That got it.  Thanks-
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question