admin管理员组

文章数量:1425734

As title says, is there a way to send form when element outside of form is clicked? Plus, is it available without using form associated (button/input etc.) elements?

As example, can form be submitted when div 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 associated (button/input etc.) elements?

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

Share Improve this question asked Jul 23, 2010 at 15:22 tomsseisumstomsseisums 13.4k20 gold badges88 silver badges148 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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();

本文标签: javascriptIs there a way to send form when element outside of form is clickedStack Overflow