Side navigation
#6920 closed bug (worksforme)
Opened August 19, 2010 06:59PM UTC
Closed August 21, 2010 12:09AM UTC
$('select').val('value') stopped working in 1.4.2
Reported by: | leo_koester | Owned by: | |
---|---|---|---|
Priority: | Milestone: | ||
Component: | manipulation | Version: | 1.4.2 |
Keywords: | val() | Cc: | |
Blocked by: | Blocking: |
Description
jQuery 1.4.2 cannot set a <select> through 'val()'.
The following code works fine with 1.3.2, but 1.4.2 doesn't:
HTML:
<select name="venCod" class="prevNext" onChange="alert(this.value)">
<option value="123">Item 1</option>
<option value="456">Item 2</option>
<option value="789">Item 3</option>
<option value="012">Item 4</option>
<option value="345" selected>Item 5</option>
<option value="678">Item 6</option>
<option value="901">Item 7</option>
<option value="234">Item 8</option>
<option value="567">Item 9</option>
</select>
SCRIPT:
$("select.prevNext")
.before("<a href=# class=prev ><</a>")
.after("<a href=# class=next >></a>")
.siblings("a.prev,a.next")
.click(function(){
var $sel = $(this).siblings("select");
if ( $(this).hasClass("prev") ) var cod = $sel.children("option[selected]").prev("option").val();
else var cod = $sel.children("option[selected]").next("option").val();
if ( cod ) $sel.val(cod).change();
status = cod + ' = ' + $sel.val();
});
The last item is always selected when the links are clicked, no matter what is the option selected before.
If I set "multiple" to <select>, every item were selected when "a.prev"/"a.next" was clicked.
Attachments (1)
Change History (1)
Changed August 21, 2010 12:09AM UTC by comment:1
resolution: | → worksforme |
---|---|
status: | new → closed |
The attached complete test case works for me on Firefox 3.6.8, IE8, Safari 5, and Chrome 5. It's basically the same as your code snippet.