back to Overview

.values()

Creates a name/value map from the given form.
Web module only.

Syntax Variants

list.values()
list.values(dataMap)

Parameters

dataMap (optional)
an optional map to write the values into. If not given, a new empty map will be created
(return value)
a map containing name->value pairs, using strings as name and value. If there is more than one value with the same name, values() creates an array containing all values.

Description

Creates a name/value map from the given form. values() looks at the list's form elements and writes each element's name into the map, using the element name as key and the element's value as value. As there can be more than one value with the same name, the map's values are arrays if there is more than one value with the same name in the form. If an element does not have a name, its id will be used. Elements without name and id will be ignored.

values() will use all elements in the list that have a name, such as input, textarea and select elements. For form elements in the list, all child form elements will be serialized.

The map format returned by values() is exactly the format used by request().

Please note that when you include an input element more than once, for example by having the input itself and its form in the list, the value will be included twice in the list.

Example

Serialize a form and send it as request parameters:

$.request('get', '/exampleService', $('#myForm').values(), resultHandler);

Example

Serialize only some selected input fields:

var data = $('#myText, input.myRadios').values();

See also..

  • $.request() can submit form data serialized by values() as HTTP POST.

Comments

comments powered by Disqus

back to Overview

Functions