Reputation: 15374
At the moment I am just trying to get jquery to show an alert when my submit button is pressed in my form, I have given it an id
<%= submit_tag "search", :id => 'submitForm' %>
and tried this
$(document).ready(function() {
$('#submitForm').submit(function(e) {
e.preventDefault();
alert('clicked');
});
});
but i get no alert, I have also tried
$(document).ready(function() {
$(':input#submitForm').submit(function(e) {
e.preventDefault();
alert('clicked');
});
});
but this doesnt work either..is there anything i am doing that is obviously incorrect
Thanks
Upvotes: 1
Views: 372
Reputation: 144669
submit
event is fired for form elements, not submit buttons, as your element is an input/button element with type of submit, you should select your form element instead:
$(function(){
$('#theForm').submit(function(e) {
// ...
});
});
Upvotes: 1
Reputation: 3822
The submit event can only be attached to forms, not to submit tags. You need to put the ID on your form.
<%= form_tag "/", id: "submitForm" do %>
<%= submit_tag "search" %>
<% end %>
Upvotes: 1