JavaScript Browser Objects Part 2
In this JavaScript tutorial, you will learn about Browser Objects viz button object properties of button object, form, name, value, Methods of button object, checkbox object, properties of checkbox object – checked, defaultChecked, form, name, type, value, Methods of checkbox object – blur(), click() and focus().
button object:
The button object is a browser object in JavaScript that is used to access a form button other than submit or reset. The button object is a property of the form object.
General syntax of button object in JavaScript is as follows:
<INPUT TYPE="button" NAME="some button name" VALUE="some value" onClick="Functionname">
For example:
<INPUT TYPE="button" NAME="Exforsys" VALUE="For Training Click Here!!!" onClick="TrainingFunc">
The above would create a button with a caption on the button:
For Training Click Here!!!
When the button is clicked, the function TrainingFunc is called. The function call is optional and when it is placed, the corresponding function must also be placed.
Properties of button object:
The following are the properties associated with button object:
- form
- name
- value
form:
form property of button object denotes the form object that includes the button.
name:
name property of button object denotes the name of the button.
value:
value property of button object denotes the value of the button that appears on the button.
Methods of button object:
The most commonly used method of button object is the click() method. The click() method invokes when the user clicks the button.
checkbox object:
Checkbox is a field that allows multiple selections for the user from a group. The checkbox object of JavaScript is used to access a checkbox that is present in a form. The checkbox object is a property of the form object.
General syntax of checkbox object in JavaScript is as follows:
<INPUT TYPE="checkbox" NAME="some name" VALUE="some value" CHECKED onClick="Functionname">
For example:
<INPUT TYPE="checkbox" NAME="Exforsys" VALUE="2" CHECKED onClick="Testfunc">
In the above example, the attributes CHECKED and onClick are optional and the TYPE, NAME and VALUE are mandatory. The above statement creates a checkbox that belongs to a group. If it is selected or checked, the value given in the parameter (in this example 2) is returned followed by invocation of the function Testfunc.
The following are the properties associated with checkbox object:
- checked
- form
- name
- type
- value
checked:
checked property of checkbox object indicates that the value is true when the button is checked.
defaultChecked:
defaultChecked property of checkbox object has the value true if the checkbox object by default is in checked state.
form:
form property of checkbox object indicates the form object, including the checkbox button.
name:
name property of checkbox object denotes the name of the checkbox button
type:
type property of checkbox object denotes the type of element as checkbox.
value:
value property of checkbox object denotes the value of the button.
Methods of checkbox object:
- blur()
- click()
- focus()
blur():
The blur() method of JavaScript belongs to the checkbox object and takes the focus away from the checkbox.
click():
The click() method of JavaScript belongs to the checkbox object and is used to indicate the checkbox as clicked as if the user has clicked it.
focus():
The click() method of JavaScript belongs to the checkbox object and is used to give the focus to the checkbox.