开发者

Is there a way to send form when element outside of form is clicked?

开发者 https://www.devze.com 2023-01-09 02:45 出处:网络
As title says, is there a way to send form when element outside of form is clicked? Plus, is it available without using form associate开发者_如何学Cd (button/input etc.) elements?

As title says, is there a way to send form when element outside of form is clicked? Plus, is it available without using form associate开发者_如何学Cd (button/input etc.) elements?

As example, can form be submitted when div is clicked?


Sure:

<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>


document.getElementById("formName").submit();


To submit the form, you can call form.submit().


Sure, assign an id to that form.

Once you click the desired element (button/input/div) you can do somthing like this in javascript

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

精彩评论

暂无评论...
验证码 换一张
取 消