471,881 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,881 software developers and data experts.

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 1119
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
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.