Jeremy Stone
Jeremy Stone

Reputation: 350

Linking to other pages in HTML via drop-down menu

I'm trying to link to other html pages via dropdown, and I've tried various codes but can't seem to get it to work. I'm using this code:

    <form name="dropdown">
<select name="list" accesskey="target">
<option selected>Choose a theme</option>
<option value="index.html">Theme 1</option>
<option value="theme2.html">Theme 2</option>
<option value="theme3.html">Theme 3</option>
<select>
<input type=button value="Go" onclick="goToNewPage(document.dropdown.list)">

I have different html pages laid out differently to alternate between layouts, how can I get this to work?

Upvotes: 6

Views: 72282

Answers (1)

The Alpha
The Alpha

Reputation: 146191

You may try this

<form>
<select name="list" id="list" accesskey="target">
    <option value='none' selected>Choose a theme</option>
    <option value="index.html">Theme 1</option>
    <option value="theme2.html">Theme 2</option>
    <option value="theme3.html">Theme 3</option>
</select>
<input type=button value="Go" onclick="goToNewPage()" />
</form>

JS: (Put this code into your <head>...</head> secion)

<script type="text/javascript">
    function goToNewPage()
    {
        var url = document.getElementById('list').value;
        if(url != 'none') {
            window.location = url;
        }
    }
</script>

Upvotes: 14

Related Questions