문제

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;
}
도움이 되었습니까?

해결책

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.

다른 팁

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top