jQ, On dropdownlist change/selection, get request on same url with ?somekey=selected-item-value
When someone selects a drop down list item, I want to redirect to the same page but with the query string set with
www.example.com/?somekey=selected-value
where selected-value
is the numeric value of the option.
I am using jQ开发者_开发知识库uery if that makes it easier.
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();
});
});
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();
});
});
精彩评论