DNR
DNR

Reputation: 3736

Javascript error : Message: Expected ')'

I am getting a javascript error below, but I can't seem to find the problem:

*Message: Expected ')' Line: 431 Char: 220 Code: 0

URI: http://mywebsite/CustomerLogin.aspx*

Line 431 is this javascript line:

<script language='Javascript'>
    var varDateNow = new Date();
    var varTimeNow = varDateNow.getTime();
    var varAlertTime = document.getElementById('cphTopContent_AlertTime').value;
    if(varTimeNow - varAlertTime < 1500)
        {alert('2' values you entered were not valid:\n\nLog In -  This value requires at least 6 characters. \nPassword -  This value requires at least 4 characters. \n');}
</script>  

What is causing the javascript error?

Upvotes: 2

Views: 9073

Answers (4)

LMS
LMS

Reputation: 4207

{alert('2' values you entered were not valid:\n\nLog In -  This value requires at least 6 characters. \nPassword -  This value requires at least 4 characters. \n');}

Should be

{ alert("2 values you entered were not valid:\n\nLog In -  This valid requires at least 6 characters.\nPassword -  This value requires at least 4 charactersn\n"); }

You messed up a few quotes, so the bracket that should end alert() was actually a string.

Upvotes: 4

Alfabravo
Alfabravo

Reputation: 7569

The alert message must be a string. Hence, after the '2', it just doesn't understand what you want to do with all the chars and stuff.

alert("blah blah '2' more blah and blah " + variableSomething + "finalBlah");

Upvotes: 1

CD..
CD..

Reputation: 74096

<script language='Javascript'>
    var varDateNow = new Date();
    var varTimeNow = varDateNow.getTime();
    var varAlertTime = document.getElementById('cphTopContent_AlertTime').value;
    if(varTimeNow - varAlertTime < 1500)
        {alert('2 values you entered were not valid:\n\nLog In -  This value requires at least 6 characters. \nPassword -  This value requires at least 4 characters. \n');}
</script> 

Upvotes: 4

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

You have a missing open quote. Try taking out the close quote after the 2 in the alert. Here's what happened behind the scenes: Since you closed the quotes after the 2, you're actually opening a new set of quotes at the end of the line after the \n. So the compiler interprets everything following that point as a string, and thus it never finds the closing parenthesis.

Upvotes: 11

Related Questions