Reputation: 25
I am trying to create a JavaScript link onclick
.
My html:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da" >
<head>
<script type="text/javascript" >
var 22 = 'http://www.google.com';
function www(url) { window.open(url); }
</script>
</head>
<body>
<img style="width: 468px; height: 60px; border: 0pt none;" src="http://dk.orvillemedia.com/ads/banners/386/468x60.jpg" onclick="javascript:www(22);" alt="468x60">
</body>
</html>
Upvotes: 0
Views: 403
Reputation: 816404
Variables cannot start with a number in JavaScript.
var google = 'http://www.google.com';
and
onclick="www(google);"
will work.
This will make the code work, but if you are going to write more JavaScript code, I suggest you read the MDC JavaScript Guide and quirksmode.org - Introducation to Events first.
Upvotes: 0
Reputation: 943547
Identifiers cannot start with numbers.
var 22 = 'http://www.google.com';
is an error.
www(22)
passes a Number, not a variable.
Upvotes: 1