Checkbox Validation not working?
-
Hello all. I am attempting to create a form with multiple validations. I have validations currently for First name and Email here: <script type="text/javascript"> function validateForm() { var x=document.forms["schedule"]["firstname"… if (x==null || x=="") { alert("First name must be filled out"); return false; } var x=document.forms["schedule"]["email"].va… var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } </script> Those validations work, however when I try to add a validation for a checkbox "terms of agreement" the validation doesnt seem to work. For checkbox validation I add: if(!document.schedule.agree.checked) { alert("Please check the terms and conditions"); return false; } I am adding this to the end of the current validation. I understand that by adding an if statement after the "email if statement " I am only adding to those if statements, but how would i avoid this error?
-
Answer:
I'm guessing you inherited this code? The checkbox is trivial compared to the other stuff. I am not comfortable with the use of... document.schedule.agree.checked I would prefer... document.getElementById('agree').checked ...where an id="agree" has been added to the checkbox.
David at Yahoo! Answers Visit the source
Related Q & A:
- Is there email validation baked in to Rails 3?Best solution by coverhound.com
- Is it OK to increase validation checks and decrease min gradient while training neural network?Best solution by Cross Validated
- How to style the HTML5 form validation messages?Best solution by Stack Overflow
- how to insert multiple rows from MySQL with checkbox?Best solution by Stack Overflow
- How to disable button when checkbox is checked. vbscript?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.