Use image to submit the form instead of using button to submit the form

Use image to submit the form instead of using button to submit the form

Copy code
The code is as follows:

<form method="post" action="formtest.html" target="_blank" name="formtest">
<input type="hidden" name="userid" value="userid">
<input type="hidden" name="username" value="username">
<input type="image" src="imagesubmit.gif" border="0">
</form>

I don't want to use a button to submit the form, I want to use a better-looking image to submit

If you write it like that, it will be submitted twice, once by the input itself, and once by the js script. There are several ways to use an image as a submit button:
1.

Copy code
The code is as follows:

<form method="post" action="formtest.jsp">
<input type="hidden" name="userid" value="userid">
<input type="hidden" name="username" value="username">
<input type="image" src="imagesubmit.gif" border="0">
</form>

As the author himself wrote, this is completely possible.
2.

Copy code
The code is as follows:

<script>
function formsubmit(){
document.formtest.action="formtest.jsp";
document.formtest.submit();
}
</script>
<form method="post" name="formtest">
<input type="hidden" name="userid" value="userid">
<input type="hidden" name="username" value="username">
<img src="imagesubmit.gif" border="0" onclick="formsubmit()">
</form>

This method is often used in mixed programming, such as when the parameters you want to submit change with the dynamically retrieved content.

<<:  Vue implements small notepad function

>>:  Solution to installing vim in docker container

Recommend

Four ways to switch tab pages in VUE

Table of contents 1. Static implementation method...

A brief discussion on how to write beautiful conditional expressions in JS

Table of contents Multiple conditional statements...

Security considerations for Windows server management

Web Server 1. The web server turns off unnecessar...

Detailed summary of mysql sql statements to create tables

mysql create table sql statement Common SQL state...

30 minutes to give you a comprehensive understanding of React Hooks

Table of contents Overview 1. useState 1.1 Three ...

Using puppeteer to implement webpage screenshot function on linux (centos)

You may encounter the following problems when ins...

Web Design Tutorial (3): Design Steps and Thinking

<br />Previous tutorial: Web Design Tutorial...

How to implement on-demand import and global import in element-plus

Table of contents Import on demand: Global Import...

How to upload and download files between Linux server and Windows system

Background: Linux server file upload and download...

JavaScript source code for Elimination

JavaScript to achieve the source code download ad...

JavaScript to implement image preloading and lazy loading

This article shares the specific code for impleme...

Mybatis paging plug-in pageHelper detailed explanation and simple example

Mybatis paging plug-in pageHelper detailed explan...