An Auto Submit Form Using JavaScript/ Javascript auto submit a form after a few seconds/ How do I automatically submit a form without clicking?

Hello Friends, In this blog post(Auto Submit Form Using JavaScript), I am going to let you know how to make an auto-submit form using javascript?

Usually, when you fill up any form you get an option ‘submit’ for submitting your form|Auto Submit Form Using JavaScript|

But here we are going to explain to you to develop an auto-submit form|Auto Submit Form Using JavaScript|

Using this functionality(Auto Submit Form Using JavaScript), when the form will be completely filled then it will be automatically submitted to the respective database after a set time says 20 sec.

Here, in this blog post(Auto Submit Form Using JavaScript), we will explore several things like How do I submit a form automatically? How do I automatically submit a form without clicking? How do you post a form using JavaScript? Javascript auto submits the form after a few seconds.

What is this auto-submit form and what is the benefit of this form? / Javascript auto submit a form after a few seconds|Auto Submit Form Using JavaScript?

A form without an option of auto-submit is known as an auto-submit form. Here the timer is set in the form.

If the timer time is 20 sec then the form will automatically submit after 20 sec.

The form will not be submitted until you fill all the fields correctly.

If you fail to submit the information under time or fill in the wrong information then a timer will again start from the beginning.

If you fill any field wrong then a popup will appear to refill the field with correct data and then finally form will be submitted.

You don’t have any worry about the form timer as a form will not be submitted until you fill it correctly.

You can use this functionality where you have a sensitive form necessarily to be filled.

this is also very useful in the case of online question paper forms where students don’t worry about the final

submission of the test paper as having very limited time to submit their form.

You can see the auto form sample in the below image.

Auto-Submit Form Using JavaScript


Software Used:

Install NetBeans IDE.

Install Xampp Server.

What is the procedure to develop this auto form functionality? / How do I submit a form automatically?

This is a very simple procedure to develop the form, you just need to follow the below step-by-step procedure for the same.

Start your Apache server using the Xampp control panel.

Open your NetBeans IDE and create a project say ‘Formautosubmit’ though you can have any name as per your wish.

Create a few files as shown in the below image under this project.


Now copy and paste the below code one by one to the respective files given below.

Auto Submit Form Using JavaScript: Code Script


<title>AutoSubmit Form Example Using JavaScript</title>
<!– Include CSS File Here–>
<link href=”formautosubmit.css” rel=”stylesheet” type=”text/css”/>
<!– Include JS File Here–>
<script src=”formautosubmit.js” type=”text/javascript”></script>
<div class=”container”>
<div class=”main”>
<form action=”success.html” method=”post” id=”form”>
<h2>AutoSubmit Form Example Using JavaScript</h2>
<span>Form will automatically submit in <b id=”timer”>20</b> <b>seconds</b>.</span>
<label>Name :</label>
<input type=”text” name=”name” id=”name” placeholder=”Name” />
<label>Email :</label>
<input type=”text” name=”email” id=”email” placeholder=”Valid Email” />
<label>Gender :</label>
<input type=”radio” name=”gender” value=”Male” id=”male” />
<input type=”radio” name=”gender” value=”Female” id=”female” />
<label>Contact No. :</label>
<input type=”text” name=”contact” id=”contact” placeholder=”Contact No.” />


window.onload = function() {
// Onload event of Javascript
// Initializing timer variable
var x = 20;
var y = document.getElementById(“timer”);
// Display count down for 20s
setInterval(function() {
if (x <= 21 && x >= 1) {
y.innerHTML = ” + x + ”;
if (x == 1) {
x = 21;
}, 1000);
// Form Submitting after 20s
var auto_refresh = setInterval(function() {
}, 20000);
// Form submit function
function submitform() {
if (validate()) // Calling validate function
alert(‘Form is submitting…..’);
// To validate form fields before submission
function validate() {
// Storing Field Values in variables
var name = document.getElementById(“name”).value;
var email = document.getElementById(“email”).value;
var contact = document.getElementById(“contact”).value;
// Regular Expression For Email
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
// Conditions
if (name != ” && email != ” && contact != ”) {
if (email.match(emailReg)) {
if (document.getElementById(“male”).checked || document.getElementById(“female”).checked) {
if (contact.length == 10) {
return true;
} else {
alert(“The Contact No. must be at least 10 digit long!”);
return false;
} else {
alert(“You must select gender…..!”);
return false;
} else {
alert(“Invalid Email Address…!!!”);
return false;
} else {
alert(“All fields are required…..!”);
return false;


[code css]
/* Below line is used for online Google font */
@import url(‘’);
background-color: #dadad4;
padding: 30px 35px;
margin: -10px -50px;
border-radius: 10px 10px 0 0;
display: block;
margin-top: 10px;
text-decoration: none;
border: 1px solid rgb(0, 143, 255);
background-color: rgb(0, 214, 255);
padding: 3px 20px;
border-radius: 2px;
color: black;
font-size: 31px;
margin: 10px -50px;
border: 0;
border-top: 1px solid #ccc;
margin-bottom: 25px;
width: 900px;
height: 610px;
margin:35px auto;
font-family: ‘Oswald’, sans-serif;
width: 306px;
padding: 10px 50px 0px;
border: 2px solid gray;
border-radius: 10px;
font-family: raleway;
margin-top: 30px;
background-color: #eae0e0;
margin-left: 240px;
width: 100%;
height: 40px;
padding: 5px;
margin-bottom: 25px;
margin-top: 5px;
border: 2px solid #ccc;
color: #4f4f4f;
font-size: 16px;
border-radius: 5px;
margin: 10px 10px 0 10px;
color: #464646;
text-shadow: 0 1px 0 #fff;
font-size: 14px;
font-weight: bold;
font-size: 16px;
background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
border: 1px solid #e5a900;
color: #4E4D4B;
font-weight: bold;
cursor: pointer;
width: 100%;
border-radius: 5px;
padding: 10px 0;
background: linear-gradient(#ffdd7f 5%, #ffbc00 100%);


<!DOCTYPE html>
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
<title>Form Submitted</title>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<div><h1 style=”text-align: center;”>Your Form has been submitted successfully</h1></div>
<a href=”formautosubmit.html”><h3 style=”text-align: center;”>Back</h3></a>

Now you are ready to run and test your project. Run the HTML file to fill out the auto-submit form.


So, in this blog post(Auto Submit Form Using JavaScript), we have learned How to submit a form automatically? How do I automatically submit a form without clicking? How do you post a form using JavaScript? and we have also explored the Javascript auto-submit the form after a few seconds, Auto submit form jQuery, JavaScript form action submit, JavaScript form submit, Auto submit the form on change

In case of any queries, you can write to us at a5t[email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post-Auto Submit Form Using JavaScript.

Please feel free to give your important feedback in the comment section below|Auto Submit Form Using JavaScript|

Have a great time! Sayonara!


I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.