views:

579

answers:

2

I just want to create a dropdown list whenever I choose a new value inside it will take me to a new webpage. I don't want to let user to click "GO" button to go to the page. Just on select and call the action. How can I do such ?

<form>
<p align="center"><b>Select a Site </b>
<select id="setit" style="color: #0000FF" size="1" name="test">
<option value="">Select one</option>
    <option value="http://www.altavista.com"&gt;AltaVista&lt;/option&gt;
    <option value="http://www.yahoo.com"&gt;Yahoo&lt;/option&gt;
     <option value="http://www.google.com"&gt;Google&lt;/option&gt;&lt;/select&gt;
     <input type="button" value="Go"
onclick="window.open(setit.options[setit.selectedIndex].value)">
</p></form>

Here for example, this will have the GO button and need to click the GO in order to go to the new page. I don't want the GO button.

Any ideas?

+5  A: 

use onchange event:

<select onchange="window.open(this.value,'','');">
....
</select>
jerjer
Note that this will fail epically if the user has Javascript turned off, so you should have a "Go" button by default and hide it with JS.
Chuck
+1 Better than mine, and heed Chucks Call. Don't want users unable to navigate.
Kyle Rozendo
how do i hide it ?
Jonathan
Of course if javascript is disabled, even if you have a go button this doesn't make sense from the client side, you cannot open a link to a new window. For purposes of working on both scenarios independent of javascript I suggest to use links (anchors) for this to work.
jerjer
Do not use <select> tag use <a> tag instead if you want them to work independently with javascript
jerjer
A: 

As fas as I understood - you simply have to handle onchange event for select tag. Just move your onclick handler there.

cleg