Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function validate(f){
- var checked = new Array();
- var errors = new Array();
- a = document.getElementsByTagName('input');
- for(i = 0; i < a.length; i++) {
- if(a[i].type == 'checkbox' && a[i].checked==true) {
- checked.push(a[i]);
- }
- }
- if(checked.length == 0) {
- errors.push('You must select at least one service');
- }
- if(f.firstName.value == "") {
- errors.push("You forgot to enter your first name.");
- f.firstName.focus();
- }
- if (f.lastName.value == ""){
- errors.push("You forgot to enter your last name.");
- f.lastName.focus();
- }
- if(f.email.value == "") {
- errors.push("You forgot to enter your email address.");
- f.email.focus();
- }
- if(f.phone.value == "") {
- errors.push("You forgot to enter a phone number.");
- f.phone.focus();
- }
- if(errors.length == 0) {
- return true;
- }
- else {
- document.getElementById("errors").innerHTML = errors.join("<br />")
- return false;
- }
- }
Add Comment
Please, Sign In to add comment