Created
February 22, 2011 08:55
-
-
Save matatabi/838389 to your computer and use it in GitHub Desktop.
Trigger rails 3 form submit without using the submit button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function send(){ | |
// check "send_now" and submit using ajax | |
// Assumes you're using jquery.rails.js | |
$("#send_now").val("true"); | |
$("#f").trigger("submit"); | |
}; | |
</script> | |
<input type='hidden' id='send_now' name='send_now' /> | |
<button type="button" onclick="send();" class='btn gray_btn'><%= t('action.send') %></button> | |
DONT'T FORGET the hidden field - it must have a name and the id must match the reference in the javascript. | |
Also, make sure the form ID is f (or whatever you reference in the javascript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment