1

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>';
3
  • I was unable to reproduce your error. See this jsFiddle Demo Commented Sep 19, 2013 at 2:10
  • Thanks for your reply. Would you mind taking a look here: audarya.org/kurssit/alkeiskurssit Commented Sep 19, 2013 at 13:52
  • Never mind...got it worked out now by changing the function name. Commented Sep 19, 2013 at 17:49

2 Answers 2

2

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.

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

3 Comments

@user2740305 Change the function name you're using: function goSomewhere() perhaps.
@user2740305 - If this answer solved your issue, can you please select the green checkmark to help future visitors troubleshoot by indicating this worked for you?
@MikeW - Perhaps you can edit your suggestion from your comment into your answer.
1
<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.

Comments

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.