Changing it with jQuery select doesn't show selected option -
i have hidden form few select fields , input fields. click on button should show form , set values in fields. input fields filled given values have problem select fields.
using code:
$("#form select[name=user]").val(value); option value gets attribute "selected" (checked in firebug) select field still shows "choose" (initial) option.
i tried focus , blur after setting value didn't work either.
any suggestions?
this pretty standard form:
<form action="#" id="form" class="fix"> <div class="holder"> <label>user:</label> <select name="user" class="styled"> <option value="0" selected>choose</option> <option value="1">user 1</option> <option value="2">user 2</option> </select> </div> </form> and calling jquery statement:
$("#form select[name=user]").val('2'); $("#form").show(); i in firebug:
<form action="#" id="form" class="fix" style="display:none"> <div class="holder"> <label>user:</label> <select name="user" class="styled"> <option value="0">choose</option> <option value="1">user 1</option> <option value="2" selected>user 2</option> </select> </div> </form> but text select stays "choose". if submit form, value correctly passed.
than if reset form , select option text of selected option shown properly. that's what's weird me.
i found solution. forgot call change event . didn't know jquery doesn't automatically. code solution is:
$("form select[name=user]").val(value).change();
Comments
Post a Comment