HTML Dom tutorial 22-html Dom form object
1: form object
The form object represents an HTML form.
Every time <form> appears in an HTML document, the form object is created.
2: form objectSetIntegration
Set |
Description |
IE |
F |
O |
W3C |
Elements [] |
Array containing all elements in the form. |
5 |
1 |
9 |
Yes |
3: form object attributes
Attribute |
Description |
IE |
F |
O |
W3C |
Acceptcharset |
The server's acceptable character set. |
No |
No |
No |
Yes |
Action |
Set or return the action attribute of the form. |
5 |
1 |
9 |
Yes |
Enctype |
Sets or returns the MIME type used to encode the content. |
6 |
1 |
9 |
Yes |
ID |
Sets or returns the ID of the form. |
5 |
1 |
9 |
Yes |
Length |
Returns the number of elements in the form. |
5 |
1 |
9 |
Yes |
Method |
Sets or returns the HTTP Method for sending data to the server. |
5 |
1 |
9 |
Yes |
Name |
Set or return the form name. |
5 |
1 |
9 |
Yes |
Target |
Set or return the frame or window name of the Form submission result. |
5 |
1 |
9 |
Yes |
4: Standard Properties
Attribute |
Description |
IE |
F |
O |
W3C |
Classname |
Sets or returns the class attribute of an element |
5 |
1 |
9 |
Yes |
Dir |
Sets or returns the direction of Text |
5 |
1 |
9 |
Yes |
Lang |
Sets or returns the language code for an element |
5 |
1 |
9 |
Yes |
Title |
Sets or returns an element's advisory title |
5 |
1 |
9 |
Yes |
5. form object Method
Method |
Description |
IE |
F |
O |
W3C |
Reset () |
Reset all input elements of the form to their default values. |
5 |
1 |
9 |
Yes |
Submit () |
Submit the form. |
5 |
1 |
9 |
Yes |
6: form object event handle
Event handle |
Description |
IE |
F |
O |
W3C |
Onreset |
Called before resetting the form element. |
5 |
1 |
9 |
Yes |
Onsubmit |
Called before submitting a form. |
5 |
1 |
9 |
Yes |
7: Submit () method
This method submits a form in the same way as clicking the submit button, but the onsubmit event handle of the form is not called.
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function formsubmit (){
Document. getelementbyid ("myform"). Submit ()
}
</SCRIPT>
</Head>
<Body>
<Form ID = "myform" Action = "js_form_action.asp" method = "get">
Firstname: <input type = "text" name = "firstname" size = "20"> <br/>
Lastname: <input type = "text" name = "lastname" size = "20"> <br/>
<Input type = "button" onclick = "formsubmit ()" value = "Submit">
</Form>
</Body>
</Html>
8: reset () method
The result of calling this method is similar to that of clicking the reset button, but the event handle onreset of the form is not called.
<HTML>
<Head>
<SCRIPT type = "text/JavaScript">
Function formreset ()
{
Document. getelementbyid ("myform"). Reset ()
}
</SCRIPT>
</Head>
<Body>
<Form ID = "myform">
Name: <input type = "text" size = "20"> <br/>
Age: <input type = "text" size = "20"> <br/>
<Br/>
<Input type = "button" onclick = "formreset ()" value = "reset">
</Form>
</Body>
</Html>