HTML and CSS Reference
In-Depth Information
Table 11.7 Properties of the elements Object
Property
What It Describes
form
The name of the form object where the element was defined (read-
only).
name
The name of the input device as specified in the HTML name attribute
(read-only).
type
The type of input device, such as radio, checkbox, password, and so
on (read-only).
disabled
A Boolean value; if true the element is disabled so that it can't be
modified; even if it contains a value, data from a disabled form field is
not sent back to the server.
value
The text that is associated with the input device, such as the text
entered into the text area or textbox, the text that appears in a button,
and so on (read/write).
11.4.3 Naming Forms and Buttons
How JavaScript References a Form by name or id . The <form> tag has a name
attribute that allows you to give your form a name. It is somewhat easier and more read-
able to reference a form by its name than by using the array syntax, such as forms[0] and
forms[1] . You will need the name attribute if you are submitting the form to a server-side
program as discussed in Section 11.4.1.
Any object, including the form, can also be referenced by using its unique ID and the
getElementById() method of the document, standardized by the W3C DOM.
In Example 11.6, two HTML forms are created: One contains a textbox, and the other
a button. Each of the forms is given a name with the name attribute and an id . In the
JavaScript program, the two forms are accessed by using the name and the id of the form
and its elements.
EXAMPLE 11.6
<html>
<head><title>Naming Forms object</title></head>
<body>
1
< form name="form1" id=”first_form” >
Enter your name:
2
<input type="text"
id="namefield"
name="namefield"
value="Name: " />
3
</form>
 
 
Search WWH ::




Custom Search