Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.10.1 setting non existing value on select

Can someone explain this behavior:

<select id ="test">
       <option value="-1">---All---</option>
       <option value="1">first</option>
       <option value="2">second</option>
</select>

$('#test').val(200);

Using the jQuery 1.10.1 the value of the select is null, but using jQuery 1.9.1 the value is the first option.

jsFiddle

like image 771
gyosifov Avatar asked Apr 10 '14 09:04

gyosifov


1 Answers

Using the jQuery 1.10.1 the value of the select is null, but using jQuery 1.9.1 the value is the first option.

It's the fix to bug #13514, fixed in v1.10. Setting an invalid value should clear the select (which it does in v1.10+), not leave it at the default (first) option (v1.9).

like image 76
T.J. Crowder Avatar answered Sep 24 '22 14:09

T.J. Crowder