6

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?

Jeremy Stone
  • 350
  • 4
  • 12
  • 29

1 Answers1

14

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>
Steve Hall
  • 113
  • 1
  • 7
The Alpha
  • 143,660
  • 29
  • 287
  • 307