function validate(){ var name = document.registration.name.value; var address = document.registration.address.value; var phone = document.registration.phone.value; var email = document.registration.email.value; var price = document.registration.price.value; var how_many = document.registration.how_many.value; if (document.registration.on_sale[0].checked) { var on_sale = document.registration.on_sale[0].value; } else { if (document.registration.on_sale[1].checked) { var on_sale = document.registration.on_sale[1].value; } else { var on_sale = ""; } } if (name != "") { if (address != "") { if (phone != "") { if (IsNumeric(phone)) { if (email != "") { if (isEmail(email)) { if (price != "") { if (IsPrice(price)) { if (on_sale != "") { if (IsNumeric(how_many) || how_many == "") { document.registration.action="registration.php"; document.registration.method= "post"; document.registration.submit(); } else { alert ("'How Many Gore-Tex Items' is not Numeric"); document.forms[0].elements[21].select(); document.forms[0].elements[21].focus(); } } else { alert ("Please select 'Yes' or 'No' for 'On Sale'"); document.forms[0].elements[17].select(); document.forms[0].elements[17].focus(); } } else { alert ("Price is not Numeric"); document.forms[0].elements[16].select(); document.forms[0].elements[16].focus(); } } else { alert ("Price is Blank"); document.forms[0].elements[16].select(); document.forms[0].elements[16].focus(); } } else { alert ("Email address is Invalid"); document.forms[0].elements[6].select(); document.forms[0].elements[6].focus(); } } else { alert ("Email is Blank"); document.forms[0].elements[6].select(); document.forms[0].elements[6].focus(); } } else { alert ("Phone Number is Not Numeric"); document.forms[0].elements[5].select(); document.forms[0].elements[5].focus(); } } else { alert ("Phone Number is Blank"); document.forms[0].elements[5].select(); document.forms[0].elements[5].focus(); } } else { alert ("Address is Blank"); document.forms[0].elements[4].select(); document.forms[0].elements[4].focus(); } } else { alert ("Name is Blank"); document.forms[0].elements[0].select(); document.forms[0].elements[0].focus(); } } function isEmail(string) { if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } function IsNumeric(strString) // check for valid numeric strings { var strValidChars = "0123456789-"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; } function IsPrice(strString) // check for valid numeric strings { var strValidChars = "0123456789.,"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; }