469,322 Members | 1,648 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

Function not working

I am trying to create a script that will have a drop down menu and will load the web page selected .
For some reason my function doesnot load the web page selected on the drop down menu What i am doing wrong here?

Any help will be appreciated

This is the function :
function loadPage(){
var sel_idx = document.demo.menu.selectedIndex
var urlToLoad = document.demo.menu.options[sel_idx].value

location.href = urlToLoad
}
This is the code:

<FORM NAME="demo">
<SELECT NAME="menu" onChange="loadPage()">
<OPTION VALUE="default2.htm">web1
<OPTION VALUE="les.htm">web2
<OPTION SELECTED VALUE="Default.htm">web3
<OPTION VALUE="webpage4.htm">web4
<OPTION VALUE="webpage5.htm">web5
</SELECT>
</FORM>
Jun 9 '07 #1
1 1087
epots9
1,351 Expert 1GB
i've tested your script and it works for me, i think your problem is u forgot the enclose your script in the script tag.
[HTML]
<html>
<head>
<title>my site</title>
<script type="text/javascript">
function loadPage(){
var sel_idx = document.demo.menu.selectedIndex
var urlToLoad = document.demo.menu.options[sel_idx].value

location.href = urlToLoad
}
</script>
</head>
<body>
<FORM NAME="demo">
<SELECT NAME="menu" onChange="loadPage()">
<OPTION VALUE="default2.htm">web1
<OPTION VALUE="les.htm">web2
<OPTION SELECTED VALUE="Default.htm">web3
<OPTION VALUE="webpage4.htm">web4
<OPTION VALUE="webpage5.htm">web5
</SELECT>
</FORM>
</body>
</html>
[/HTML]
Jun 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by =?Utf-8?B?SmVycnkgQw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.