Reputation: 11
I have a simple javascript dropdown menu that I’m getting an HTML5 validation error. The error is “Bad value goto(this); for attribute onchange on element select: identifier is a reserved word.” Can anyone help me out with what to change in the code:
<script>
<!--
function goto(choose){
var selected=choose.options[choose.selectedIndex].value;
if(selected != ""){
location.href=selected;
}
}
//-->
</script>
<strong><SELECT onChange="goto(this);"></strong>
<option value="">--Choose studio--</option>
<option value="[home]/studio-1/">Studio 1</option>
<option value="[home]/studio-2">Studio 2</option>
</SELECT>';
Upvotes: 1
Views: 232
Reputation:
Believe it or not, goto
is a reserved word in Javascript, even though it's not implemented.
You should change the function name you're using - function gotoSomewhere()
, perhaps.
Upvotes: 2
Reputation: 76593
<script>
<!--
function goThere(choose){
var selected=choose.options[choose.selectedIndex].value;
if(selected != ""){
location.href=selected;
}
}
//-->
</script>
<strong><SELECT onChange="goThere(this);"></strong>
<option value="">--Choose studio--</option>
<option value="[home]/studio-1/">Studio 1</option>
<option value="[home]/studio-2">Studio 2</option>
</SELECT>';
goto is a reserved word in Javascript, use a different name instead as in the example above.
Upvotes: 1