开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜