user961946
user961946

Reputation: 29

syntax issue with JS /HTML nesting quotations

I get this error: "missing ) after argument list" from firebug running this script. I attempted to us /' to nest the parameters in my window.open equation. Can anyone see what's wrong here?

onclick="getinfo(); setTimeout('window.open(/'checkout.php/', /'_self/', /'location=yes/', /'false/')',10000);"

Upvotes: 1

Views: 72

Answers (3)

Bennett McElwee
Bennett McElwee

Reputation: 25750

As Dave said, move the code out of the onclick and it will be much clearer:

onclick="myFunction()"

<script>
function myFunction() {
  getinfo();
  setTimeout(function() {
      window.open('checkout.php', '_self', 'location=yes', 'false')
    },
    10000);
}
</script>

You could be more unobtrusive that this too, but this is a good start and it solves your quoting problem.

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160181

Quotes should be escaped with backslashes.

(Yet another reason to try and be a bit more unobtrusive with your JavaScript!)

Upvotes: 2

Clive
Clive

Reputation: 36957

The forward slashes need to be back slashes

onclick="getinfo(); setTimeout('window.open(\'checkout.php\', \'_self\', \'location=yes\', \'false\')',10000);"

Upvotes: 2

Related Questions