Reputation: 1195
Using Rails, I am submitting a form that generates a new url each time the form is submitted. How can I catch the url of the new form? I tried something like the following but can't get it to work
$('#addSyn').click(function(ev){
url = $(this).attr('href');
$('#expURL').text(url);
});
HTML/Rails
<section style="width:45%; right:0; position:absolute;">
<%= form_for @exp, remote: true, :id => 'EditForm' do |f| %>
<%= f.label :Syn %><br>
<%= f.text_field :syn %><br>
<%= f.label :Exp %><br>
<%= f.text_field :exp %><br>
<%= f.submit "Add Syn", :id=>"addSyn" %>
<% end %>
<div id="ExpURL">
</div>
</section>
Upvotes: 0
Views: 99
Reputation: 10663
You only get #addSyn
using $(this)
inside $('#addSyn').click
. And the case seems wrong(if it's not a typo), it should be #ExpURL
.
Try:
$('#EditForm').on('submit', function(){
url = $(this).attr('action');
$('#ExpURL').text(url);
});
Also you can use prop
instead of attr
.
Upvotes: 1