tags:

views:

28

answers:

1

Using jQuery, what is the most simple and elegant way to re-select an item in a <select> dropdown list when given chosen_value=111?

What if it is checkboxes instead of <select>, having id[]=11&id[]=12... (the [] are actually in %5B%5D)

+1  A: 

For the dropdownlist, just set the value using the val() function.

$("#mySelect").val(chosen_value);

For the checkboxes, you can set all the values at once if you can get the array of checkbox names that should be checked.

$("input[type=checkbox]").val(["checkbox1", "checkbox3", "checkbox4"]);
womp