Question

Can anyone explain why below example does not work? I'd like to impelment dropdown that will redirect to other sites based on the option selected.

http://jsfiddle.net/5swk8/6/

function go()
{
    window.location=document.getElementById("menu-dropdown").value;
}
Was it helpful?

Solution

It is saying as 'Uncaught ReferenceError: go is not defined' because the go() method is wrapped in onload. Change the wrap option to body, then it will work.

OTHER TIPS

In the Frameworks & Extensions panel, set onLoad to No wrap - in <body>.it will work

DEMO

Without a separate function

<select id="mySelect" onChange="document.location = this.value" value="GO">
    <option>Select</option>
    <option value="http://www.microsoft.com">Test</option>
</select>

Demo: http://jsfiddle.net/2ekmM/1/

You have an error in redirecting the page. It is

window.location.href="";

your code is right only thing you have move your go function inside body I updated your code in jsfiddle.

jsfiddle.net/mannejkumar/5swk8/11/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top