Skip to main content

Bug Tracker

Side navigation

#1663 closed bug (fixed)

Opened September 18, 2007 10:58PM UTC

Closed December 04, 2007 08:45AM UTC

.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 September 18, 2007 11:00PM UTC.
Change History (1)

Changed December 04, 2007 08:45AM UTC by davidserduke comment:1

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