Javascript call before submitting form on rails

I am trying to call a javascript function to check some data on a form, and if they are ok, fill in the form field (hidden field).

After this step I want to clear some form fields and continue the post action of the form.

Thus, the result of my controller will be this hidden field filled with my javascript logic, and the rest of the fields will be cleared.

How to do it on Rails 4?

Thanks in advance

+4
source share
1 answer

you can try something like:

$(function() {

  $('button').click(function(e){
    e.preventDefault();
    //DO SOMETHING
    $('YOURFORM').submit();
  }
})

I hope this helps

+7
source

All Articles