Morph9090 Morph9090 - 7 months ago 25
Javascript Question

Uncaught Syntax Error: Unexpected token if

if (fname == null || fname == "") {


Getting "uncaught syntax error:unexpected token if in line 13". It says "SyntaxError: missing variable name" in Javascript lint

function validateregistration() {

var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname = document.form.user_firstname.value,
lname = document.form.user_lastname.value,
uname = document.form.username.value,
femail = document.form.email.value,
freemail = document.form.verify_email.value,
fpassword = document.form.password.value,


if (fname == null || fname == "") {
document.form.user_firstname.focus();
document.getElementById("errorBox")
.innerHTML = "enter the first name";
return false;
}
if (lname == null || lname == "") {
document.form.user_lastname.focus();
document.getElementById("errorBox")
.innerHTML = "enter the last name";
return false;
}

if (femail == null || femail == "") {
document.form.email.focus();
document.getElementById("errorBox")
.innerHTML = "enter the email";
return false;
} else if (!emailRegex.test(femail)) {
document.form.Email.focus();
document.getElementById("errorBox")
.innerHTML = "enter the valid email";
return false;
}

if (freemail == null || freemail == "") {
document.form.verify_email.focus();
document.getElementById("errorBox")
.innerHTML = "Re-enter the email";
return false;
} else if (!emailRegex.test(freemail)) {
document.form.enterEmail.focus();
document.getElementById("errorBox")
.innerHTML = "Re-enter the valid email";
return false;
}


if (fpassword == null || fpassword == "") {
document.form.password.focus();
document.getElementById("errorBox")
.innerHTML = "enter the password";
return false;
}

}

Answer

This line doesn't properly terminate the var statement:

fpassword = document.form.password.value,

Use a semicolon at the end of the line:

fpassword = document.form.password.value;

if (fname == null || fname == "") {
Comments