Is there a way to submit a form when I click an item outside the form?

As the title says, is there a way to submit formwhen an element is clicked outside the form? Also, is it accessible without the use of formrelated ( button/ inputetc.) Elements?

As an example, you can send formwhen you click div?

+3
source share
4 answers

Of course:

<form name="myForm" action="" method="post">
    <!-- form inputs go here -->
</form>

<div id="formSubmit"></div>

<script type="text/javascript">
    var myForm = document.forms['myForm'];
    var formSubmit = document.getElementById('formSubmit');

    formSubmit.onclick = function(){
        myForm.submit();
    }
</script>
+4
source
document.getElementById("formName").submit();
+2
source

, form.submit().

+1

, .

(button/input/div), - javascript

$("#YourFormId").submit();
0

Source: https://habr.com/ru/post/1756213/


All Articles