form object

form object

A

tag is a object.


Properties of the form object

  • name: The name of the form, mainly used to let JS control the form.

  • action: form data processing program (PHP file).

  • method: form submission method, values: GET, POST

  • enctype: encoding method of form data.


Methods of form object

  • submit(): Submit the form, the same function as .

  • reset(): Reset the form, which has the same function as the reset button.


Events of the form object

  • onsubmit: Occurs when the submit button is clicked, and occurs before the data is sent to the server. Mainly used for "form validation before form submission".

  • onreset: Occurs when the reset button is clicked.

    php.cn  
用户名: 密码:


##Get form elements

  • Get the object through the id of the web page element. document.getElementById(id)

  • Get the object through the HTML tag name. parentNode.getElementsByTagName(tagName)

  • Get the form element object through the name attribute. The starting point of all elements in the form must be a document object.

  • Syntax: document.formObj.elementObj

  • The access method is a three-tier structure. Among them, formObj represents the form object, and elementObj represents the form element object.

  • Example: document.form1.username.value.length


##Event return value
The return value of the event will affect the default action of the object. For example: The default action of the tag is to open a URL.

If the event returns false, the execution of the default action is prevented; if the event returns true or empty, the default action continues to be executed.

    php.cn 
PHP中文网

There are two events affected by the return value: onclick and onsubmit.

Continuing Learning
||
php.cn
用户名: 密码:
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!