nonopolarity
nonopolarity

Reputation: 150976

How to re-select something in a <select> element using jQuery?

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)

Upvotes: 0

Views: 93

Answers (1)

womp
womp

Reputation: 116977

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"]);

Upvotes: 1

Related Questions