views:

36

answers:

4

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?

+1  A: 

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

Douglas
+1  A: 
document.getElementById("formName").submit();
This doesn't seem to work..
Tom
@Tom: this should work. Have you checked that your form **id** (not name) is what you pass to `getElementById`?
nico
A: 

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();
Mahesh Velaga
You should specify that this is the "JQuery way" to do that. Other solutions (the ones using `document.getElementById`) do not need external libraries.
nico
Check the tags, OP used JQuery :)
Mahesh Velaga
@Mahesh Velaga: sorry didn't see that :) Still, better to specify for any other reader that does not necessarily look at the tags (like I did) and maybe arrives here from a Google link.
nico
+2  A: 

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>
kevinmajor1
Thanks, that's exactly what I was looking for!
Tom