How to submit a form without clicking a submit button?

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

with accessing tag name you can use the .submit() method  of JavaScript for it .

Let’s Say You Have One Form Where You Using Div instead of submit button .

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

Now There is two Ways You Can Do This

Sol 1 ::  by TagName ;

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

Whenever user Click On Div Form Get Sumitted.



Sanket replied 3 years ago

Subscribe

Select Categories