There are several ways to submit a form. Generally, we are used to submit a form using a submit button. However, sometimes we have to submit a form using a specific event or by clicking an HTML element.
There are several ways to submit a form using JavaScript. Even more, we can also submit a form on some event on the webpage.
Here we are going to learn to submit a form without the submit button.
The most simple way to submit a form without the submit button is to trigger the submit event of a form using JavaScript.
In the below example we are going to create a function to submit a form. We will set that function at onclick event of a div tag.
<!DOCTYPE html>
<html>
<head>
<title>Submit a form using JavaScript onclick event</title>
</head>
<body>
<form id="my_form" action-xhr="#" method="POST">
<input type="text" name="name" placeholder="Enter Your Name"/>
<br/>
<input type="email" name="email" placeholder="Enter Your E-mail"/>
<br/>
<textarea placeholder="Enter Your Message" name="message"></textarea>
<br/>
<div >
Read Also: OnClick Form Validation Using jQuery
Here we submitted the form using a JavaScript function onclick event of div element. We can also set many other types of events to submit a form. I hope now you understand how to submit a form using JavaScript event without a submit button.
Enjoy Scripting 🙂
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
We can redirect any webpage to any other or redirect the whole domain or website…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…