Reputation: 21
Hi i have one listbox with some values. i want to select it's value based on a value in array list using JSTL. My code is something like that
<select id='lstType' name="lstType">
<option value="abc" selected="yes">abc</option>
<option value="bcd">bcd</option>
<option value="efg">efg</option>
</select>
and a arraylist having some object of entity class.
class entity{
String str;
}
Now on jsp page i am fetching like this
$("#lstCategory option[value = <c:out value="${entity.str}"/>]").attr("selected", true);
Upvotes: 1
Views: 778
Reputation: 20323
Instead of attr use prop
$('#lstType option[value="${entity.str}"]').prop("selected", "selected");
Edit:
Use above only if you are in jQuery 1.6 if using before version use
$('#lstType option[value="${entity.str}"]').attr("selected", "selected");
Upvotes: 2
Reputation: 13139
Try to use this statement:
$('#lstType option[value="${entity.str}"]').attr("selected", "selected");
Upvotes: 1