Solved

Auto Check a checkbox when user begins typing in textbox

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now