Reputation:
Say I have:
<form>
<select>
<option value="page1.html">Page 1</option>
<option value="page2.html">Page 2</option>
</select>
<input type="submit" value="Submit">
</form>
How do I make it so that when I select an option, I click on this Submit button and it goes to the appropriate link that was selected?
Upvotes: 1
Views: 1513
Reputation: 116
You can try this code.
<form>
<select onchange="if (this.value) window.location.href=this.value">
<option value="page1.html">Page 1</option>
<option value="page2.html">Page 2</option>
</select>
<input type="submit" value="Submit">
</form>
Thanks
Upvotes: 1
Reputation: 62536
You can use this code:
$(function() {
$('#frm1').on('submit', function() {
window.location = $('#sel1').val();
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="frm1">
<select id="sel1">
<option value="page1.html">Page 1</option>
<option value="page2.html">Page 2</option>
</select>
<input type="submit" value="Submit">
</form>
Note that in the example it will not works, since there are no such pages on stackoverflow's server
Upvotes: 0