2

My script is working, but there is one thing I can not solve.

  $(function () {
        $('#form_<?php echo $i; ?>' ).on('submit', function (e) {
          e.preventDefault();
          $.ajax({
            type: 'post',
            url: 'akcija_gaz_2l_insert.php',
            data: $('#form_<?php echo $i; ?>').serialize(),
            success: function () {
                //alert('form is submited');
            }
          });
          $("submit, input[type='submit']").click(function()
          {
          $(this).prop('disabled', true);
          $(this).css("color", "#15FF00");
          });
        });
      });

On first click it's submitting the form and on 2nd click it is disabling the button and changing the color to green. Can someone explain to me why it requires two clicks for this function? I want to do both on one click.

0

2 Answers 2

1

Try this,in your success function disable the button and change the button color like below

success: function(){
     $("#bttonID").attr("disabled", true);
     $("#bttonID").css("background","#15FF00");
},
Sign up to request clarification or add additional context in comments.

3 Comments

no prob mate and don't forget to make it as write answer
dont understand what u mean by write answer? @shakir
their is write mark below the vote you have to click that to accept the answer meta.stackexchange.com/questions/5234/…
1

It requires two clicks because you are handling click event only when submit has happened. You should handle button change in the success function, or directly in the submitting function.

$(function () {
    $('#form_<?php echo $i; ?>' ).on('submit', function (e) {
      e.preventDefault();
      $.ajax({
        type: 'post',
        url: 'akcija_gaz_2l_insert.php',
        data: $('#form_<?php echo $i; ?>').serialize(),
        success: function () {
            //alert('form is submited');
            $("submit, input[type='submit']").prop('disabled', true);
            $("submit, input[type='submit']").css("color", "#15FF00");
        }
      });
    });
  });

1 Comment

Thxs for explanation @hulothe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.