Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4047 closed bug (worksforme)

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

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 (1)

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

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by dmethvin

Attachment: test-4047.html added

Working example

comment:1 Changed 11 years ago by dmethvin

Resolution: worksforme
Status: newclosed

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 11 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.

Note: See TracTickets for help on using tickets.