my javascript code is only validating one field at a time (as in it validates on field then submits the form, instead of going through the entire thing and then returning it as true and submitting it…)
I’m not sure what to do to be honest, I’ve looked up google to no real avail..
my variables are declared in a seperate file to the actual even handlers and I have heaps of comments through out it, so please don’t judge lol i’m still learning ?
[QUOTE]
//Event Registrations (Variable Declarations) found in validation_chkr.js
//Validate Entire Form using validate_join()
function validate_join()
{
//Validate Mobile Phone Numer Entered
if (posmobile != 0) {
alert (“The phone number (” + llphone.value +
“)is not in the correct format n” +
“Please re-enter your mobile number”);
mphone.focus();
mphone.select();
return false;
}
//Validate Occupation Selected
if(occupation.selectedIndex==0)
{
alert(“Please select an Occupation from the List”);
occupation.focus();
occupation.select();
return false;
}
//Validate Landline Phone Numer Entered
if (poslandline != 0) {
alert (“The phone number (” + llphone.value +
“)is not in the correct format n” +
“Please re-enter your landline number”);
llphone.focus();
llphone.select();
return false;
}
//Validate Email Field
if (pos != 0) {
alert(“The email supplied(” + email.value +
“) is not a valid email address. n” +
“Please re-enter your email address”);
email.focus();
email.select();
return false;
}
//Validate Surname Field
if(surname.value == “”){
alert(“Please enter surname”);
surname.focus();
return false;
}
//Validate Othername Field
if(othername.value == “”){
alert(“Please enter othername”);
othername.focus();
return false;
}
// Validate Address Field (if address 1 has nothing in it or address 2 has nothing in it then alert user
if(address1.value == “” && address2.value == “”){
alert(“Please enter Delivery Address”);
address1.focus();
return false;
}
//Validate Username Field
if(username.value == “”){
alert(“Please enter username”);
username.focus();
return false;
}
//Check if White Space Appears in Username Field
else if(!re.test(username.value)) {
alert(“Error: Username must contain only letters, numbers and underscores!”);
username.focus();
return false;
}
//Check Length of Username Field (between 6 and 10 characters)
else if((username.value).length < 6 || (username.value).length >10){
alert(“username must composed of 6-10 digits”);
username.focus();
return false;
}
//Validate Password Field
if(password1.value != “” && password1.value == password2.value) {
if(password1.value.length < 6) {
alert(“Error: Password must contain at least six characters!”);
password1.focus();
return false;
}
//Check Username is Different to Password
if(password1.value == username.value) {
alert(“Error: Password must be different from Username!”);
password1.focus();
return false;
}
//Check Password contains a Minimum of one Number
if(!re2.test(password1.value)) {
alert(“Error: password must contain at least one number (0-9)!”);
password1.focus();
return false;
}
//Check Password contains one Lower Case Letter
if(!re3.test(password1.value)) {
alert(“Error: password must contain at least one lowercase letter (a-z)!”);
password1.focus();
return false;
}
//Check Password contains on Upper Case Letter
if(!re4.test(password1.value)) {
alert(“Error: password must contain at least one uppercase letter (A-Z)!”);
password1.focus();
return false;
}
}
//Validate Postcode Field (if nothing present alert user)
if(postcode.value == “”){
alert(“Please enter postcode”);
postcode.focus();
return false;
}
//Validate Postcode Field (if something other than a number is entered then alert user)
else if(IsNumeric(postcode.value) == false){
alert(“Please enter postcode (Numbers only)”);
postcode.focus();
return false;
}
return true;
}
Variables:
[QUOTE]
//validation_chkr.js
//Event Registrations for validation_chk.js
//Surname Variable Registered
var surname = document.getElementById(“surname”)
//Othername Variable Registered
var othername = document.getElementById(“othername”)
//Address Line 1 Variable Registered
var address1 = document.getElementById(“address1”)
//Address Line 2 Variable Registered
var address2 = document.getElementById(“address2”)
//Postcode Variable Registered
var postcode = document.getElementById(“postcode”)
//Username Variable Registered
var username = document.getElementById(“username”)
// Password and User Name Restrictions Registered – The reason I did not use multiple/ ‘look ahead’ regular expressions is due to older browswers
// Not being supported, therefore possibly not recognising the appropriate regular experessions
var re = /^w+$/
var re2 = /[0-9]/
var re3 = /[a-z]/
var re4 = /[A-Z]/
//Password 1(Initial) Variable Registered
var password1 = document.getElementById(“initial”)
//Password 2(Second) Variable Registered
var password2 = document.getElementById(“second”)
//Occupation Variable Registered
var occupation = document.getElementById(“occupation”)
//Contact Method Variable Registered
var radios = document.getElementsByName(“contactmethod”)
//Email Variable Registered
var email = document.getElementById(“email”)
//Email Restrictions Registered
var pos = email.value.search(/^.+@.+.
//Emailreturn Variable Registered (used to compare with pos for pattern matching)
var emailreturn = 0;
//Landline Variable Registered
var llphone = document.getElementById(“landline”);
//Landline Restrictions Registered
var poslandline = llphone.value.search(/^d{2}-d{3}-d{3}$/)
//Landline Variable Registered
var mphone = document.getElementById(“mobile”);
//Landline Filter REgistered
var posmobile = mphone.value.search(/^d{2}-d{4}-d{4}$/)
if someone could help (without changing my coding too much if possible) i’d be very appreciative ?
THANKS