Bug Tracker

Modify

Ticket #6920 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 years ago

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

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

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

Change History

Changed 4 years ago by dmethvin

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to worksforme

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.