I want to use a select menu to redirect to another page in Rails.
I tried to add link_to to the select tag but it does not work.
How can this be done?
I want to use a select menu to redirect to another page in Rails.
I tried to add link_to to the select tag but it does not work.
How can this be done?
You would need to use Javascript and the onClick event on the Select Element
<script type="text/javascript">
function navigate(value) {
switch (value) {
case "1":
document.location.href = "http://www.google.com";
break;
case "2":
document.location.href = "http://www.yahoo.com";
break;
}
}
</script>
<select onchange="navigate(this.value)" >
<option selected>Please Choose</option>
<option value="1"> this page </option>
<option value="2"> that page </option>
</select>