chintu
chintu

Reputation: 195

My jquery submit handler is not called in Chrome

My jquery submit handler is not called in Chrome. Here is the code:

<input
accesskey="s"    
class="button"    
id="issue-link-submit"
name="Link"
title="Press Alt+s to submit this form"
type="submit"
value="Link"
/> 

<script type="text/javascript">
jQuery('#issue-link-submit').submit(function() {
alert('hi');
});
</script>

But it is working fine in IE and FF. Could you please help me on this? Thanks in advance!

-Chintu

Upvotes: 2

Views: 2721

Answers (3)

Tushar Ahirrao
Tushar Ahirrao

Reputation: 13115

Change your javascript code to this:

$("formId").submit(function() {
   alert('hi');
   return true;
});

Replace #issue-link-submit with your form id. If there is no form id, then add an id to the form.

You can not add #issue-link-submit selector to submit handler directly, because you are adding submit handler to the button. You need to add the submit handler to the form element.

Upvotes: 0

rickyduck
rickyduck

Reputation: 4084

Try:

<script type="text/javascript">
jQuery('#issue-link-submit').click(function(e) {
    e.preventDefault;
    alert('hi');
});
</script>

Upvotes: 1

hayesgm
hayesgm

Reputation: 9096

As scripts execute before the page is necessarily parsed and rendered, you must wrap all jQuery code which depends on the DOM in a document.ready callback.

 <script type="text/javascript">
   jQuery(document).ready(function() {
     jQuery('#issue-link-submit').submit(function() {
       alert('hi');
       return false; //prevent default?
     });
   }
 </script>

Upvotes: 0

Related Questions