Bug Tracker

Opened 7 years ago

Closed 7 years ago

#6920 closed bug (worksforme)

$('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:


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 >&lt;</a>") .after("<a href=# class=next >&gt;</a>") .siblings("a.prev,a.next")


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.

Change History (1)

comment:1 Changed 7 years ago by dmethvin

  • Resolution set to worksforme
  • Status changed from new to 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.

Note: See TracTickets for help on using tickets.