Skip to main content

Bug Tracker

Side navigation

#7773 closed bug (fixed)

Opened December 14, 2010 05:58AM UTC

Closed December 14, 2010 07:22AM UTC

Last modified April 23, 2011 06:14PM UTC

val() documentation contains misleading example

Reported by: spud@nothingness.org Owned by:
Priority: low Milestone: 1.5.1
Component: web Version: 1.4.4
Keywords: Cc: kswedberg
Blocked by: Blocking:
Description

The 2nd example on the documentation page for the setter-version of val() ("Set a single select and a multiple select") contains 4 inputs (2 checkboxes, 2 radio buttons), and some example code that reads

$("input").val(["check1","check2", "radio1" ]);

The effect of that code is to select two of the checkboxes and one of the radio buttons. Of course, if there were a simple ''text'' input field on the same page, its content would be set to "check1,check2,radio1", which is stupid. So bad example code for that reason alone.

However, since the only "input" fields on the page are checkboxes or radio buttons, and the example code successfully checks them, it seems reasonable to infer that

$("input:checkbox").val("check1");

would check the first checkbox. It does not. It sets the value of ALL checkboxes to "check1" (which makes sense, syntactically). But the inference would appear reasonable to a newbie.

To further confuse things,

$("input:checkbox").val(["check1"]);

with a single-element ''list'' for parameters, does successfully check the first box (and unchecks the 2nd, if it had been checked). Now that just seems weirdly sloppy, since the documentation gives no indication that using a list of parameters somehow behaves differently from a single string parameter.

I just figured this could be cleaned up a bit.

Attachments (0)
Change History (6)

Changed December 14, 2010 06:24AM UTC by rwaldron comment:1

component: unfiledattributes
keywords: → needsdoc
priority: undecidedlow
status: newopen

Changed December 14, 2010 06:28AM UTC by rwaldron comment:2

cc: → kswedberg

@kswedberg i'm pulling you into this just so its on record

Changed December 14, 2010 07:22AM UTC by danheberden comment:3

resolution: → fixed
status: openclosed

Changed the documentation to more accurately describe the use of an array as .val()'s argument.

Changed December 14, 2010 11:50PM UTC by jitter comment:4

keywords: needsdoc

Changed December 15, 2010 12:06AM UTC by spud@nothingness.org comment:5

You are all awesome. Thanks!

Changed April 23, 2011 06:14PM UTC by john comment:6

component: attributesweb
milestone: 1.61.5.1