Hello Readers,
If I want to Select Drop down Option Value after Click on Button
(not submit) then we use the below code:
<select name="option">
<option value="http://findnerd.com">Findnerd</option>
<option value="http://facebook.com">Facebook</option>
<option value="http://twitter.com">Twitter</option>
</select>
<button type="button" onclick="openLink(document.forms['myForm1'])">Click</button>
<form name="myForm2" method="post">
<select name="option">
<option value="http://linkedin.com">Linkedin</option>
<option value="http://google.com">Google</option>
</select>
<button type="button" onclick="openLink(document.forms['myForm2'])">Click</button>
</form>
<script type="text/javascript">
function openLink(myForm)
{
var selectedIndex = myForm.elements["urls"].selectedIndex;
var url = myForm.elements["urls"].options[selectedIndex].value;
window.open(url);
}
</script>
0 Comment(s)