What are the form methods in javascript

青灯夜游
Release: 2021-11-04 18:02:01
Original
3746 people have browsed it

There are two form methods built into JavaScript, namely: 1. reset(), used to reset all input elements of the form to their default values; 2. submit(), used to reset the form Data is submitted to the web server.

What are the form methods in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The Form object represents an HTML form.

In an HTML document, a Form object is created every time

appears.

Form users are usually used to collect user data and contain input elements such as: text fields, check boxes, radio buttons, submit buttons, etc. Forms can also include options menus, textarea, fieldset, legend, and label elements.

The form is used to send data to the server.

Javascript form object (form) methods:

Method Description
reset() Reset all input elements of the form to their default values.
submit() Submit the form.

The reset() method of the Form object

The reset() method can reset the elements in the form to their default value.

Syntax: formObject.reset()

Description: The result of calling this method is similar to the result of the user clicking the Reset button, except that the form's event handle onreset will not is called.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function formReset(){
	document.getElementById("frm1").reset();
}
</script>
</head>
<body>

<p>在下面的输入框中输入一些文本,然后按下“重置表单”按钮重置表单。</p>
<form id="frm1">
用户名: <input type="text" name="name"><br>
密 码: <input type="password" name="password"><br><br>
<input type="button" onclick="formReset()" value="重置表单">
</form>

</body>
</html>
Copy after login

What are the form methods in javascript

submit() method of Form object

submit() method Submit the form data to the web server.

Syntax: formObject.submit()

Description: This method submits the form in the same way as the user clicks the Submit button, but the onsubmit event handler of the form will not be called.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function formSubmit(){
	document.getElementById("frm1").submit();
}
</script>
</head>
<body>

<p>在下面的输入框中输入一些文本,然后按下“提交表单”按钮提交表单。</p>
<form id="frm1" action="form_action.asp">
用户名: <input type="text" name="name"><br>
密 码: <input type="password" name="password"><br><br>
<input type="button" onclick="formSubmit()" value="提交表单">
</form>

</body>
</html>
Copy after login

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What are the form methods in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!