Function not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Theadmin77
    New Member
    • Nov 2006
    • 19

    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.m enu.selectedInd ex
    var urlToLoad = document.demo.m enu.options[sel_idx].value

    location.href = urlToLoad
    }
    This is the code:

    <FORM NAME="demo">
    <SELECT NAME="menu" onChange="loadP age()">
    <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>
  • epots9
    Recognized Expert Top Contributor
    • May 2007
    • 1352

    #2
    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.m enu.selectedInd ex
    var urlToLoad = document.demo.m enu.options[sel_idx].value

    location.href = urlToLoad
    }
    </script>
    </head>
    <body>
    <FORM NAME="demo">
    <SELECT NAME="menu" onChange="loadP age()">
    <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]

    Comment

    Working...