Submit the form with image instead of button

Time:2020-10-15

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>

You don’t want to submit the form using button, but you want to submit it with a better looking image

In that case, the input will be submitted twice, the input itself will be submitted once, and the JS script will be submitted again
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 landlord 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. For example, the parameters you want to submit will change with the content extracted dynamically