instance method Form.Element#getValue

View source on GitHub →

Form.Element#getValue() → String | Array

Returns the current value of a form control.

A string is returned for most controls; only multiple select boxes return an array of values.

The global shortcut for this method is $F.

How to reference form controls by their name

This method is consistent with other DOM extensions in that it requires an element ID as the string argument, not the name of the form control (as some might think). If you want to reference controls by their names, first find the control the regular JavaScript way and use the node itself instead of an ID as the argument.

For example, if you have an input named "company" in a form with an ID "contact":

var form = $('contact');
var input = form['company'];
 // but, the preferred call is:
$(input).getValue(); // we used the $() method so the node gets extended
 // you can also use the shortcut

An error is thrown ("element has no properties") if the element argument is an unknown ID.

Alias of: $F

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.