Hi developers,
I have a form where customers can register thierselves by entering the relevant fields.
There is a control() javascript which ckecks if everything on the form is ok before submitting it.
Althugh IE applies the script for every check, Firefox does only apply the first check (first if statement) of the script. The rest is ignored.
[U]Here is the javascript code:
function control()
{
if (document.member.FirstName.value == “”){
document.member.FirstName.focus();
alert(“Please fill the name field”);
return false;
}
if (document.member.FirstName.value.length<2) {
alert(“Name field cannot be shorter than 2 characters.”);
document.member.FirstName.focus();
return false;
}
if (/[d]/.test(document.getElementById(“FirstName”).value)) {
alert(“Entered numbers into the Name field”);
return false;
}
if (document.member.LastName.value == “”){
document.member.LastName.focus();
alert(“Please fill the Lastname field”);
return false;
}
if (document.member.LastName.value.length<2) {
alert(“Lastname field cannot be shorter than 2 charcters. Please check again.”);
document.member.LastName.focus();
return false;
}
if (/[d]/.test(document.getElementById(“LastName”).value)) {
alert(“Entered numbers into the Lastname field”);
return false;
}
if (document.member.Address1.value.length<10) {
alert(“Address field contains less than 2 characters.”);
document.member.Address1.focus();
return false;
}
if (document.member.Username.value == “”){
document.member.Username.focus();
alert(“Username field cannot be blank”);
return false;
}
if (document.member.Address1.value == “”){
document.member.Address1.focus();
alert(“Address field cannot be blank “);
return false;
}
if (document.member.City.value == “”){
document.member.City.focus();
alert(“City field cannot be blank”);
return false;
}
if (document.member.Email.value == “”){
document.member.Email.focus();
alert(“E-Mail field cannot be blank.”);
return false;
}
if (echeck(document.member.Email.value)==false){
document.member.Email.focus();
return false;
}
if (document.member.PhoneNumber.value == “”){
document.member.PhoneNumber.focus();
alert(“Phone number field cannot be blank”);
return false;
}
if (!/^d*$/.test(document.getElementById(“PhoneNumber”).value)) {
alert(“Entered characters into the Phone Number field”);
return false;
}
if (document.member.Pass.value == “”){
document.member.Pass.focus();
alert(“Password field cannot be blank.”);
return false;
}
if (document.member.Pass2.value == “”){
document.member.Pass2.focus();
alert(“Password confirmation field cannot be blank.”);
return false;
}
if (document.forms[0].Pass.value.length<6) {
alert(“Password field cannot contain less than 6 characters. Please check”);
document.member.Pass.focus();
return false;
}
if (document.member.Pass.value != document.member.Pass2.value) {
alert(“Password and password confirmation fields are not identical. Please check “);
document.member.Pass.focus();
return false;
}
if (!isTelNum(document.forms[0].PhoneNumber,’Telefon ‘)) return false;
if (!isNum(document.forms[0].InternalPhoneNumber,’Internal Phone number’)) return false;
//if (!isValidEmail(document.forms[0].Email)) return false;
return true;
}
Well interesting that only the first check is taken into consideration.
if (document.member.FirstName.value == “”){
The rest is not even seen. Even if you do not fill the rest of the form, the submit button tries to submit the form regardless what more needs to be checked.
Here is the submit button:
<input type=”submit” name=”member” value=”Register Me” id=”member” onclick=”return control()”;>
Any observations and comments are appreciated.