Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit button outside the <form> tags [duplicate]

I've been searching for two hours and I couldn't find any solutions.

I would like to have two submit buttons, one inside the < form > tag and one outside the < form > tag.

<form id="example" name="example" action="post">
    Input <input type="text" name="text" />
    <input type="submit" name="submit" value="submit" />
</form>

<div class="button">Submit</div>

JS / jQuery

$(".button").click( function() {
    alert("Button clicked");
}); 

How can I send the form with the ('.button') class outside the form ?

JS Fiddle here: http://jsfiddle.net/ZQLXb/

like image 822
Peter Avatar asked Mar 28 '13 16:03

Peter


4 Answers

Use the submit() function to trigger the form submission:

$(".button").click( function() {
    $('#example').submit();
});

You can also use the trigger() function:

$(".button").click( function() {
    $('#example').trigger('submit');
});

Although they do exactly the same thing.

like image 196
Matt Cain Avatar answered Oct 22 '22 14:10

Matt Cain


use submit() function to submit the form

$(".button").click( function() {
   $('#example').submit();
}); 
like image 42
bipen Avatar answered Oct 22 '22 14:10

bipen


You could trigger the submit event on the form:

$('#example').trigger('submit')
like image 35
davids Avatar answered Oct 22 '22 14:10

davids


$(".button").click( function() {
    $('#example').submit();
}); 
like image 38
jmoerdyk Avatar answered Oct 22 '22 14:10

jmoerdyk