title: Calling a jquery query on clicking a button
body: <p>I am trying to call a jquery function on clicking a button in the form and here is the code I am using </p>
  
  <p>Button code :</p>
  
  <pre><code>  &lt;input type="submit"  src="images/submitbutton.png" alt="Submit button" name="submit_button" class="submit_button" id="submit_button"&gt;
  </code></pre>
  
  <p>Form starting code</p>
  
  <pre><code> &lt;form method="post" action="" id="contactForm"&gt;
  </code></pre>
  
  <p>The jquery code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function() {
  
      //if submit button is clicked
      $('input[name=submit_button]').submit(function () {     
  
  
  alert("testing")
  
  .....
  </code></pre>
  
  <p>I tried everything to get the submit button to call the jquery function but to no avail ( I tried using submit() or click() ).</p>
  
  <p>What might I be doing wrong ( This form is located on a html page) </p>
  
  <p>Edit : Just inserted the code of the Jquery function I am trying to run ,I am actually trying to call a php script using ajax and then hide the form and provide a success message if the form is submitted successfully</p>
  
  <pre><code>$(document).ready(function() {
  
      //if submit button is clicked
      $('#submit_button').submit(function () {        
  
              alert("testing")    /*get the email value*/
  
  var name = $('input[name=name]');
          var email = $('input[name=email]');
          var subject= $('input[name=subject]');
          var message = $('textarea[name=message]');
  
  
   data = 'name=' + name.val() + '&amp;email=' + email.val() + '&amp;subject=' + 
          subject.val() + '&amp;message='  + encodeURIComponent(message.val());
  
  
          //disabled all the text fields
          $('.text').attr('disabled','true');
  
  
  
          //start the ajax
          $.ajax({
              //this is the php file that processes the data and send mail
              url: "mai.php", 
  
              //GET method is used
              type: "POST",
  
              //pass the data         
              data: data,     
  
  
  
              //success
              success: function () {              
  
                      $('.contact_form').fadeOut('slow');                 
  
                      //show the success message
                      $('.simple-sucess').fadeIn('slow');
  
                  //if process.php returned 0/false (send mail failed)
                  } 
  
  
  
          });
  
          //cancel the submit button default behaviours
          return false;
      }); 
  }); 
  &lt;/script&gt; 
  </code></pre>