Summary of several submission methods of HTML forms

Summary of several submission methods of HTML forms
The most common, most commonly used and most general method is to use submit type.. See the code:

Copy code
The code is as follows:

<form name=”form” method=”post” action=”#">
<input type=”submit” name=”submit” value=”Submit">
</form>

Another common method is to use pictures:

Copy code
The code is as follows:

<form name=”form” method=”post” action=”# ">
<input type=”image” name=”submit” src=”btnSubmit.jpg”>
</form>

The third method is to use a link to submit the form, using the javascript DOM model:

Copy code
The code is as follows:

<form name=”form” method=”post” action=”#”>
<a href="javascript:form.submit();">Submit</a>
</form>

This method actually calls a javascript function. Using javascript function to submit a form has many flexible methods. For example, you can add it to the onclick event of any tag:

Copy code
The code is as follows:

<form name=”form” method=”post” action=”#”>
<div onclick="javascript:form.submit();">
<span>Submit</span>
</div>
</form>

But what if a form needs to have multiple submit buttons?
For example, the submit buttons in a form point to different processing pages. Since the processing page of the form data has been determined when the form is defined, simply placing multiple submit buttons in the form will not achieve the desired result. This requires JavaScript.
First, define a function:

Copy code
The code is as follows:

<script language=javascript>
function query(){
form.action=”query.php”;
form.submit();}
function update(){
form.action=”update.php”;
form.submit();}
</script>

By changing the value of the form's action attribute through javascript, you can implement multiple submit buttons with different functions. The code on the page is as follows:

Copy code
The code is as follows:

<form name=”form” method=”post” action=”#”>
<input type=”button” name=”query” onclick=”query();” value=”query”>
<input type=”button” name=”update” onclick=”update();” value=”Update”>
</form>

The above code uses a normal button, and the submit function is implemented by calling a javascript function in its onclick event.
With the above methods of submitting forms, I think it is enough to handle complex forms.

<<:  How to install docker and portainer in kali

>>:  Possible reasons why the input type="reset" tag in HTML is invalid (does not work).

Recommend

How to bypass unknown field names in MySQL

Preface This article introduces the fifth questio...

【HTML element】How to embed images

The img element allows us to embed images in HTML...

The process of installing and configuring nginx in win10

1. Introduction Nginx is a free, open source, hig...

How to implement checkbox & radio alignment

Not only do different browsers behave differently...

Teach you how to use webpack to package and compile TypeScript code

TypeScript Bundling webpack integration Usually, ...

Restart all stopped Docker containers with one command

Restart all stopped Docker containers with one co...

Vue implements a simple timer component

When doing a project, it is inevitable to encount...

How to view and configure password expiration on Linux

With the right settings, you can force Linux user...

Tutorial on configuring and using i3 window manager in Linux

In this article, I will show you how to install a...

A comprehensive analysis of what Nginx can do

Preface This article only focuses on what Nginx c...

An Uncommon Error and Solution for SQL Server Full Backup

1. Error details Once when manually performing a ...

How to configure MGR single master and multiple slaves in MySQL 8.0.15

1. Introduction MySQL Group Replication (MGR for ...

Does Mysql ALTER TABLE lock the table when adding fields?

Table of contents Before MySQL 5.6 After MySQL 5....

Detailed explanation of several storage methods of docker containers

Table of contents Written in front Several storag...