Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning Code to a specific button

I have three forms on a page with submit buttons in each, there is a code which is suppose to changes the value of a button in a particular form when clicked but when i click on that submit button all the values in the various forms buttons changes, but i want to change the value based on the form i click

<script language="javascript">
/**
 * Disable submit button
 */
$(function(){
      $('input:submit').click(function(){
            $(this).val('Request Placed...');
            $(this).attr('disabled', 'disabled');
            $(this).parents('form').submit();
      });
});
$(window).load(function(){
      $('input:submit').removeAttr('disabled');
});
</script>
like image 435
blay Avatar asked Apr 18 '26 06:04

blay


1 Answers

Use jQuery selector to select only form that you need, only input from form with id="form_2" will be supported

$(function(){
      $('input:submit', '#form_2').click(function(){
            $(this).val('Request Placed...');
            $(this).attr('disabled', 'disabled');
      });
});

jsfiddle: http://jsfiddle.net/krzysztof_safjanowski/sP2Zv/2/

like image 163
Krzysztof Safjanowski Avatar answered Apr 20 '26 19:04

Krzysztof Safjanowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!