How can I, using jQuery, set the \"next\" item of an already selected item as \"selected.\"
For example, if I have:
Find the row, then
var row = $('#yourTable');
the value you want to select
var theValue = "5";
row.find("select:eq(2)").find("option[value="+theValue+']').attr('selected','selected');
$("select").prop("selectedIndex",$("select").prop("selectedIndex")+1)
$('#my_sel').val($('#my_sel option:selected').next().val());
$('#my_sel').val($('#my_sel option:selected').prev().val());
From version 1.6.1 on, it's advisable to use the method prop for boolean attributes/properties such as selected, readonly, enabled,...
var theValue = "whatever";
$("#selectID").val( theValue ).prop('selected',true);
For more info, please refer to to http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/
$('your_select option:selected').next('option').prop('selected', true)
And if you want to specify select's ID:
$("#nextPageLink").click(function(){
$('#myselect option:selected').next('option').attr('selected', 'selected');
$("#myselect").change();
});
If you click on item with id "nextPageLink", next option will be selected and onChange() event will be called. It may look like this:
$("#myselect").change(function(){
$('#myDivId').load(window.location.pathname,{myvalue:$("select#myselect").val()});
});
OnChange() event uses Ajax to load something into specified div.
window.location.pathname = actual address
OnChange() event is defined because it allowes you to change value not only using netx/prev button, but directly using standard selection. If value is changed, page does somethig automatically.