Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 507
Jeremy Stone Avatar asked Nov 07 '13 18:11

Jeremy Stone


People also ask

How do I make one page jump to another page in HTML?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

How do you link two pages together in HTML?

Complete HTML/CSS Course 2022 To make page links in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the link starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a link.


1 Answers

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>
like image 140
The Alpha Avatar answered Dec 04 '22 06:12

The Alpha