0

Possible Duplicate:
Disable submit button on form submit

I have a question about disable button after ajax submit. Actually the button disabled first until I input text to textarea. Then if I submit with click button, it must disable the button.

In my actual, after click button, the button isn't disabled.

Here it's my JS code :

$(function()
    {
        $("#submit_h").click(function() 
        {
            var haps = $("#haps").val();
            var dataString = 'haps='+ haps;
            if(haps=='')
            {
                alert('Please type your haps');
            }
            else
            {
                $.ajax({
                type: "POST",
                url: "post_haps.php",
                data: dataString,
                cache: false,
                success: function(html){
                $("#haps").val('');
                $("#content").prepend(html);
                }
                });
            }return false;
        });
    });

--

<textarea id="haps"></textarea>
<input type="submit" class="button inact" value="Share" disabled="disabled" id="submit_h"/>

Now what I want to do is, disabled the button after submit. Any idea ?

Community
  • 1
  • 1
Naga Botak
  • 721
  • 2
  • 9
  • 14

2 Answers2

1

Similar to NullUserException's link, you can use jquery to set the "disabled" attribute:

$(".inact").attr('disabled', 'disabled');
Mike
  • 1,559
  • 10
  • 17
  • I mean disabled after submit, not on submit. So if after submit the button must be disabled until I fill text to texarea. – Naga Botak Oct 01 '12 at 07:13
  • From a user experience, is there a difference between it being disabled "on submit" vs "after submit"? How long after they submit are you wanting to wait? Simply use the code I provided at a location in your code that corresponds with your timing needs. – Mike Oct 01 '12 at 07:17
  • Thanks for your explain, now I got the login. :) – Naga Botak Oct 01 '12 at 07:37
1

Disable the button in ajax success:

success: function(html){
                $("#haps").val('');
                $("#content").prepend(html);
                $("#submit_h").attr("disabled", true);
                       }
MJQ
  • 1,778
  • 6
  • 34
  • 60