Solved

Auto Check a checkbox when user begins typing in textbox

Posted on 2003-11-18
5
360 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

786 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