How to submit a form without clicking a submit button?

Forums JavaScriptHow to submit a form without clicking a submit button?
Staff asked 2 years ago

Answers (1)

Add Answer
Sanket Marked As Accepted
Staff answered 2 years ago

With accessing the tag name you can use the .submit() method of javaScript for it .

Let’s say you have one form where you use div instead of submit button.

<form id="form1" action="" method="POST">
<div onClick="submitForm()"></div>
</form >

Now There Are Two Ways You Can Do This

Sol 1::  By TagName ;

document.getElementsByTagName('form')[0].submit()
Sol 2 : By Id
<code> <script>
    function submitForm(){
        var form = document.getElementById("form1");
        form.submit();
        alert("Form Submitted");
    }
    </script></code>

Whenever user click on div form get sumitted

Subscribe

Select Categories