问题描述:

I have some JavaScript which will do some basic error checking on my registration form (makes sure all fields are filled, passwords match etc.) and the submit button is disabled until the fields are entered correctly. There is also a div above the form that will display which bits of the form need correcting.

The code runs fine on Google Chrome, but using IE10 it only seems to run half of the JavaScript. It prints the error messages for everything apart from the security question's answer, and the submit button stays disabled even when all fields are correct (which are the last 2 parts of the JavaScript function).

The page can be found here, and the JavaScript function contains this code:

function timerFunc() {

var success = 1;

errors.innerHTML = "";

if (fname.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Forename Required.</p>";

success = 0;

}

if (sname.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Surname Required.</p>";

success = 0;

}

if (email.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Email Required.</p>";

success = 0;

} else {

success = verifyEmail(email.value);

}

if (uname.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Username Required.</p>";

success = 0;

}

if (pword.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Password Required.</p>";

success = 0;

} else if (pword.value.length < 8) {

errors.innerHTML = errors.innerHTML + "<p>Password Must Have 8 Characters.</p>";

success = 0;

}

if ((pword1.value != "") && (pword1.value != pword.value)) {

errors.innerHTML = errors.innerHTML + "<p>Passwords Don't Match.</p>";

success = 0;

}

if (seca.value == "") {

errors.innerHTML = errors.innerHTML + "<p>Security Answer Required.</p>";

success = 0;

}

if (success == 1) {

submit.disabled = false;

} else {

submit.disabled = true;

}

}

It may be something really simple to fix it, but I don't understand why it works perfectly in Chrome and not IE. Thanks in advance, Jake.

网友答案:

In RegFunc try adding this line:

pword1 = document.getElementById("pword1");

pword1 is not defined - this is printed infinitely on the console - F12 is your friend in IE9+

相关阅读:
Top