views:

43

answers:

2

When someone selects a drop down list item, I want to redirect to the same page but with the querystring set with www.example.com/?somekey=selected-value

where selected-value is the numeric value of the option.

I am using jqeury if that makes it easier.

+1  A: 

Use the onchange event in the select element:

<select ... onchange="window.location.href='?somekey='+$(this).val();">

Or if you want to hook it up using jQuery:

$(function(){
  $('#idOfTheSelect').change(function(){
    window.location.href = '?somekey=' + $(this).val();
  });
});
Guffa
I'd consider using window.location.replace(), for reasons detailed here http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery
tomit
If the href already contains a querystring value, this will wipe it out right? hmm...maybe I can check on the server side first.
Blankman
A: 

Absolutely. Heres some code:

<select id="redirect">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
</select>

$(document).ready(function() {
    $("#redirect").change(function() {
       document.location = "product.html?id=" + $(this).val();
    });
});
Marko