Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation of a form based on checkbox value 1

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
I have a simple form.

1. I have a textarea.

2. Underneath the textarea I have a checkbox

3. I have four input fields below the checkbox.

How do I add validation for everything but only validation for the four input fields below the checkbox when the checkbox is unchecked?

I have been searching for examples but can’t find anything to meet this criteria.

Thanks.
 
your checkbox should have an id attached to it so:

//validate your text area
...
// check to see if the checkbox is checked
if (document.getElementById("cbxID").checked) {
// validate all items beneath it
...
}

return true/false based on result of validation;





TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
I just read my post and I did make a mistake...

should be

if (!document.getElementById("cbxID").checked) {
...
}

I originally read your post as if the checkbox was checked...

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top