0

How can i redirect on another page when an option is selected from a select element.

HTML select:

<select id='rooms' class="full-width">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

What i need is to redirect users to page.php when they select the option 2, 3, 4

CARASS
  • 245
  • 3
  • 16
  • Use change event of select the simply use `window.loaction.href="Your path"` – Satpal Mar 07 '15 at 11:09
  • 2
    Simply you can use `.change` event (jQuery) of dropDown and on selection of particular value, you can redirect to another page, what's the issue in that? read more about change event :http://api.jquery.com/change/ – Mox Shah Mar 07 '15 at 11:09
  • the downvote is because there are tons of examples on the internet. – gp_sflover Mar 07 '15 at 11:17

1 Answers1

1

You need to call window.location.assign in the change event handler of that select. I also presume you would need to add the value selected to the URL so that the next page knows what option was selected; for that you can use val(). Try this:

$('#rooms').change(function() {
    window.location.assign('page.php?rooms=' + $(this).val());
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339