简体   繁体   中英

How to submit a form and use the result in javascript triggered by the submit button?

I have a form_tag form that I want to submit in order to get the values. These same values I want to use in a javascript that is triggered by the same submit button I use for the form.

What I want to do is to first submit the form and then call the javascript.
My submit function looks like that:

<%= submit_tag "Submit", :onclick => "sendRequestToRecipients(); return false;" %>

but it only calls the javascript and doesn't submit the form.

If I do something like this:
:onclick => "submit();sendRequestToRecipients(); return false;"
then I only submit the form but don't call the javascript.

Can I somehow say "trigger this javascript after the form is submitted(using the result of the submission)?

My javascript looks like that:

function sendRequestToRecipients() { { options } , requestCallback); }

The problem is the return false which prevents the default action of the submit button.

Try:

<%= submit_tag "Submit", :onclick => "sendRequestToRecipients();" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM