Using these features, you can assign values to textboxes or textareas, alter values in input fields, add options to drop down menus, validate passwords etc all on the fly.
The text object represents the HTML text field <input type="text"> , to reference the value in the text field, the syntax is :
document.form.textboxes.value; , the hierarchy is represented by the diagram below:
Example: Assigning values to Text boxesGive it a TRY! » Note: Both the forms are accessed via both name and id attribute.
The password object is similar to the text object the only difference being that text do not appear, instead asterisks are displayed.
In order to have multiple lines of text, a textbox is used. represented by the object textarea
The element <select> is used to create a drop-down or a scroll box, it contains menu items called as options.
The options array also has a selectedIndex property, which represents the index number of the option being selected, starting from 0
To select multiple options, the attribute to be used is multiple. Hold down the Ctrl key and then select multiple items
If multiple items are selected, the value of selectedIndex denotes only the first selected option.
The property selected of the options object is used to show if multiple items are selected.It returns a true if multiple options are selected or else a false is returned.
A radio button has only two states, ON and OFF. When a radio button is checked it is selected, and when another option is checked, the previous options is deselected. Only one option can be selected.
Each button is a property of the object radio and are assigned to an array in an order in which they appear in the form.
The property checked of the radio object specifes whether a button is checked by returning true or else a false is returned.
To select multiple options use check boxes, a checkbox has two states, ON and OFF.
Each checkbox is a property of the object checkbox and are assigned to an array in an order in which they appear in the form.
The property checked of the checkbox object specifes whether a button is checked by returning true or else a false is returned.