Dropdown with Links and Send-Button opening in the same window?
-
09-07-2021 - |
Question
i want to have a simple dropdown to choose betwenn 5 links (pages) but i want the link-page to be opened in the same window (target _self) after klicking "send". it should be as simple as possible. this is what i have so far:
<form>
<select id="setit" style="color: #0000FF" size="1" name="test">
<option value="#">please choose</option>
<option value="http://www.altavista.com">AltaVista</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.google.com">Google</option></select>
<input type="button" value="send"
onclick="window.open(setit.options[setit.selectedIndex].value)">
</form>
is it also possible to have the first one "not clickable" (nothing should happen after clicking on "send" on this one)?
thanks, you're awesome!
Solution
Below is my modified code:
<script type="text/javascript">
function openWindow(location){
if(location == "#")return;
window.open(location,'_self');
}
</script>
<select id="setit" style="color: #0000FF" size="1" name="test">
<option value="#">please choose</option>
<option value="http://www.altavista.com">AltaVista</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.google.com">Google</option></select>
<input type="button" value="send" target="_self"
onclick="openWindow(setit.options[setit.selectedIndex].value)">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow