Bug Tracker

Opened 12 years ago

Closed 12 years ago

#1663 closed bug (fixed)

.val() causes an error on non-form elements

Reported by: olangan Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: val Cc:
Blocked by: Blocking:

Description

original bug description and test case can be found here: http://groups.google.com/group/jquery-dev/browse_thread/thread/831a7ff4a9ffdaae

I have discovered a potential bug, or at least difference between 1.1 and 1.2, when using the .val() method. Previously, when running this on a non-form element (usually a link), it would return null or perhaps undefined (a 'falsy' value). Now it generates an error which halts script execution.

Below is a stripped-down example of how I am using it in my code. The line which breaks is:

item: $.trim($(event.target).attr("src")
target.val()

target.text()),

To reproduce the error, include this script on any page, and place a breakpoint on the send(params) statement. The problem can be seen when any link is clicked: the breakpoint is never reached.

My simple workaround has been to swap the target.text() and target.val() positions in the problematic line.

Attachments (1)

val_error.js (1.7 KB) - added by olangan 12 years ago.

Download all attachments as: .zip

Change History (2)

Changed 12 years ago by olangan

Attachment: val_error.js added

comment:1 Changed 12 years ago by davidserduke

Resolution: fixed
Status: newclosed

I believe this was fixed in [3965] for #1714. .val() should no longer throw a JS error when there is no value to find (like calling $("p").val()).

Note: See TracTickets for help on using tickets.