2

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?

6
  • 9
    Wow, even SO's syntax highlighting caught this one Commented Aug 15, 2012 at 17:53
  • 1
    alert('2' values... does not look right Commented Aug 15, 2012 at 17:54
  • 2
    I highly recommend using a better text editor to write your javascript. Commented Aug 15, 2012 at 17:54
  • @jbabey... what is your preference? Commented Aug 15, 2012 at 18:41
  • @DotNetRookie Visual Studio. If anyone tells you otherwise for .NET, they're an idiot. Commented Aug 15, 2012 at 18:57

4 Answers 4

11

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.

Sign up to request clarification or add additional context in comments.

Comments

4
<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> 

1 Comment

This doesn't explain to the OP why he was getting the error he was getting. He missed it the first time, what makes you think he'll notice the difference here?
4
{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.

2 Comments

Parenthesis if you're in the States, bracket if you're a UK guy like me :) Over here parenthesis can refer to commas, like this, brackets (these things), or dashes - pretty much two hyphens - and all can be used, though I think commas are preferred.
hmm very interesting! Learn something new every day!
1

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");

1 Comment

not the reason for the error he got, the reason for the error he got is the mismatch of quotes, leading to an unterminated string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.