Bug Tracker

Opened 5 years ago

Closed 5 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:

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

test-6920.html (1.1 KB) - added by dmethvin 5 years ago.

Download all attachments as: .zip

Change History (2)

Changed 5 years ago by dmethvin

comment:1 Changed 5 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.