将代码分配给特定形式

I am trying to submit a variable on form1 using jquery which at the end disables the submit button for this form with a message "Sent Successfully".

There's another form on the page called form2 which is assigned an action to submit variables to another page without ajax call but i think my button disable code is conflicting with the form2 not making it able to send the variables to the assigned action page.

<script language="javascript">
/**
 * Disable submit button
 */
$(function(){
      $('input:submit', '#form1').click(function(){
            $(this).val('Sent Successfully...');
            $(this).attr('disabled', 'disabled');
      });
});
</script>

form2

<form id="form2" name="form2" method="post" action="search.php">
          <label for="textfield"></label>
          <input type="text" name="textfield" id="textfield" />
          <input type="submit" name="button2" id="button2" value="Submit" />
        </form>

yes it deflects because you're using two selectors, one that will disable all the submit buttons and then #form1. try changing it to:

$(function(){
      $('#form1').click(function(){
            $(this).val('Sent Successfully...');
            $(this).attr('disabled', 'disabled');
      });
});

There is no need for #form1. Just use input:submit to target the button and it should work. Keep in mind that this will also apply to the submit button of form 2 i.e when you click submit in form2 it will change the text and disable it.

$(function(){
      $('input:submit').click(function(){
            $(this).val('Sent Successfully...');
            $(this).attr('disabled', 'disabled');
      });
});

Since you are using input:submit this will disable all the submit button in that particular page.

Instead of this

$(function(){
  $('input:submit', '#form1').click(function(){
        $(this).val('Sent Successfully...');
        $(this).attr('disabled', 'disabled');
  });
});

Try using:

$(function(){
  $('#form1').on('click','input:submit',function(){
        $(this).val('Sent Successfully...');
        $(this).attr('disabled', 'disabled');
  });
});

Just try with submit event, and select the appropriate button with .find() method:

  $( '#form1' ).on( 'submit', function() {
      $(this)
          .find( '#button1' )
          .val( 'Sent Successfully...' )
          .attr( 'disabled', 'disabled' );
  });