简体   繁体   中英

Dropdown Navigation Menu Using Javascript in Wordpress

I've been working on a wordpress site for an internship and I'm wanting to embed javascript code in a page to create a dropdown menu that navigates the browser to the selected page.

I'm wondering, is there something special you need to do to allow js to work in a wp page? I tried the following code embedded in the page using the html side of posting option:

<script language="javascript" type="text/javascript">
<!--
function menu_goto( menuform )
{
    // see http://www.thesitewizard.com/archive/navigation.shtml
    // for an explanation of this script and how to use it on your
    // own site

    var baseurl = "173.236.164.86/where-to-buy/" ;
    selecteditem = menuform.newurl.selectedIndex ;
    newurl = menuform.newurl.options[ selecteditem ].value ;
    if (newurl.length != 0) {
      top.location.href = baseurl + newurl ;
    }
}
//-->
</script>

<form action="dummyvalue">
<select name="newurl" onchange="menu_goto(this.form)">
<option value="" selected="selected">----- Select A Product -----</option>
<option value="vene-prototype-version/">VENE Prototype Version</option>
<option value="configuration-vene-version/">VENE Configuration Version</option>
<option value="customized-vene-version/"> VENE Customized Version</option>
</select>
</form>

The dropdown menu appears, but fails to redirect the browser on change. I have tried surrounding the code in the page with the tags and that has no effect either.

http://173.236.164.86/where-to-buy/

thanks for the help!

Developer Tools show a parse error in your JS. Probably from WP automatically inserting paragraph returns. Remove all the white space and carriage returns in the JS and try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM