0

Here how my rails form looks like:

  - form_tag rel_references, :remote => true, :id=>"references_form", :method => 'get' do               
    = text_field_tag :rel_id, params[:rel_id], :id=>"reference_form_rel_id"
    = submit_tag "Get references", :id => "referencesubmit"

I need the textfield #reference_form_rel_id to be dynamically populated based on the HTML of a DOM element using jQuery and then submit this form (remotely) from within the same jQuery function. So this is what I am doing:

  $(".classname").live('click',function(){  
     var relationship_id = $('#id_store').html().trim();
     $('#reference_form_rel_id').val(relationship_id);  // populate the text field
     $('#references_form').submit();       // submit the form

});

Now, the form does get submitted, however, it is not submitted remotely, and the page reloads thus defeating the purpose of the :remote => true. Please guide me on how to correctly submit a rails remote form via jQuery. Thanks!

1 Answer 1

4

you may try

$('#referencesubmit').trigger('click')
Sign up to request clarification or add additional context in comments.

3 Comments

The problem persists. this to causes the form to reload.
sorry try this one $('#referencesubmit').trigger('click')
$('#referencesubmit').trigger('click') did it. Edited the answer to reflect that. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.