Form. Element

Extensions to Prototype’s Form.Element class

Summary
Extensions to Prototype’s Form.Element class
Sets the value of a form element to a given value, regardless of the type of control it is
Checks whether a given form element is a select
Checks whether a given form element is a textarea
Checks whether a given form element is an input of type text
Checks whether a given form element is an input of type hidden
Checks whether a given form element is an input of type radio
Checks whether a given form element is an input of type checkbox

Functions

setValue

Form.Element.setValue = function(element,
value)

Sets the value of a form element to a given value, regardless of the type of control it is

Parameters

elementElement, the form element to update
valueString, the new value to set

Credit

Form.Element code is based on Form.Element.setValue in prototypeUtils.js from http://jehiah.com/ Licensed under Creative Commons.  Version 1.0 December 20 2005

Example

Form.Element.setValue("title", "Mr");

isSelect

Form.Element.isSelect = function(element)

Checks whether a given form element is a select

Parameters

elementthe form element to check

Returns

booleantrue if the element is a select, false otherwise

Example

Form.Element.isSelect("title"); // true

isTextArea

Form.Element.isTextArea = function(element)

Checks whether a given form element is a textarea

Parameters

elementthe form element to check

Returns

booleantrue if the element is a textarea, false otherwise

Example

Form.Element.isSelect("title"); // false
Form.Element.isTextArea("notes"); // true

isInputText

Form.Element.isInputText = function(element)

Checks whether a given form element is an input of type text

Parameters

elementthe form element to check

Returns

booleantrue if the element is a text input, false otherwise

Example

Form.Element.isInputText("name"); // true

isInputHidden

Form.Element.isInputHidden = function(element)

Checks whether a given form element is an input of type hidden

Parameters

elementthe form element to check

Returns

booleantrue if the element is a hidden input, false otherwise

Example

Form.Element.isInputHidden("name"); // false

isInputRadio

Form.Element.isInputRadio = function(element)

Checks whether a given form element is an input of type radio

Parameters

elementthe form element to check

Returns

booleantrue if the element is a radio button input, false otherwise

Example

Form.Element.isInputRadio("name"); // false

isInputCheckbox

Form.Element.isInputCheckbox = function(element)

Checks whether a given form element is an input of type checkbox

Parameters

elementthe form element to check

Returns

booleantrue if the element is a checkbox input, false otherwise

Example

Form.Element.isInputCheckbox("agree"); // true
Form.Element.setValue = function(element,
value)
Sets the value of a form element to a given value, regardless of the type of control it is
Form.Element.isSelect = function(element)
Checks whether a given form element is a select
Form.Element.isTextArea = function(element)
Checks whether a given form element is a textarea
Form.Element.isInputText = function(element)
Checks whether a given form element is an input of type text
Form.Element.isInputHidden = function(element)
Checks whether a given form element is an input of type hidden
Form.Element.isInputRadio = function(element)
Checks whether a given form element is an input of type radio
Form.Element.isInputCheckbox = function(element)
Checks whether a given form element is an input of type checkbox