Ryan Leonard
Ryan Leonard

Reputation: 997

Why would I be getting a "missing ) after argument list" error?

I am working on an AJAX system to submit a form, but I can't even get my JavaScript to load, the Firebug report is below.

missing ) after argument list
    else if( httpRequest.responseText == 'already logged in' )\n

I poked around the internet and SO, but all I found was errors in quoting. (Example, Another Example). I don't have anything misquoted, so I really don't see what is going on. More of my code is below.
(Some unrelated function calls to remove loading messages are removed.)

if(httpRequest.responseText != "failure")  // Works fine!
{
    document.getElementById("result").innerHTML = "[Success message]";
    setTimeout("2000", function(){ window.location.assign("[link to page]");
}
else if(httpRequest.responseText == 'already logged in')  // Similar to above, but fails
{
    document.getElementById("result").innerHTML = "[error message]";
}
else
{
    document.getElementById("result").innerHTML = "[error message]";
}

Might anyone know why this error is called?
(For more members, it might be useful to outline what things cause this error, which would allow this page to work with other code)

Upvotes: 1

Views: 1897

Answers (4)

Dan
Dan

Reputation: 1888

If you split your code up a bit more you see the problem:

setTimeout("2000", function()
{
    window.location.assign("[link to page]");

So you are missing a } and a );

setTimeout(function()
{
    window.location.assign("[link to page]");
},2000);

Edit: The order of the arguments is wrong as well like Caspar pointed out.

Upvotes: 5

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

the line

setTimeout("2000", function(){ window.location.assign("[link to page]");

misses a }) causing the next line to fail (the whole syntax is wrong anyway:)

it should be

 setTimeout (function(){ window.location.assign("[link to page]") } , 2000 );

setTimeout takes a function as the first parameter and an integer as the second one.

more here

Upvotes: 7

Magnar
Magnar

Reputation: 28810

You are missing the }); here

setTimeout("2000", function(){ window.location.assign("[link to page]");

should be

setTimeout("2000", function(){ window.location.assign("[link to page]"); });

Upvotes: 2

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26699

   setTimeout("2000", function(){ window.location.assign("[link to page]");

should be

   setTimeout("2000", function(){ window.location.assign("[link to page]");});

Upvotes: 3

Related Questions