Skip to content

Instantly share code, notes, and snippets.

@matatabi
Created February 22, 2011 08:55
Show Gist options
  • Save matatabi/838389 to your computer and use it in GitHub Desktop.
Save matatabi/838389 to your computer and use it in GitHub Desktop.
Trigger rails 3 form submit without using the submit button
<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