Bug Tracker

Modify

Ticket #4047 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 years ago

Selector, <select> and val() returns inconsistent value

Reported by: nminale Owned by:
Priority: major Milestone: 1.3.2
Component: unfiled Version: 1.3.1
Keywords: Cc:
Blocking: Blocked by:

Description

Hi, I have the following code, <div id="testDiv"> <select id="testSelect"> <option value="1">One</option> <option value="2">Two</option> </select> <input type="button" id="testBtn" value="Test"> </div>

On the page, when I select "Two" from the drop down list and use JQuery to get the value of <select>, the result is inconsistent.

  1. $("div[id='testDiv'] select[id='testSelect']").val(), it returns "1".
  2. $("#testDiv").find("#testSelect").val(), it returns "1".
  3. $("#testSelect").val(), it returns "2".

Using Firebug, I saw the selectors from A and B actually return all <option> elements... So naturally, it picks the value of the first option..

With JQuery 1.2.6, A, B and C return same value.

Please advise.

Thank you.

Attachments

test-4047.html Download (764 bytes) - added by dmethvin 4 years ago.
Working example

Change History

Changed 4 years ago by dmethvin

Working example

comment:1 Changed 4 years ago by dmethvin

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

I've attached a complete test case that seems to work fine for me. You mentioned Firebug so I assume you tested in Firefox, but If I've misinterpreted the problem, please reopen and attach a test case that demonstrates the problem.

comment:2 Changed 4 years ago by nminale

Thanks for checking. I found out that it was because a plug-in that I used, jquery.validation.js -- it's not compatible with JQuery 1.3.1. After I upgraded this plugin to its latest version (1.5.1), everything works as expected.

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.