views:

243

answers:

3

Hi all,

Here is my simple function

$('#save_button').click(function() {
      $(this).attr('disabled',true).val('Saving');

      $('#new_record_form').ajaxForm({
        url: '/',
        type: "POST",
        dataType: "json",
        beforeSubmit: function(){ alert('Boo!'); },
        success: function(){ alert('Hello!'); }
      });
 });

This works fine in Firefox but not in Internet Explorer, Chrome or Safari.

Commenting out this line $(this).attr('disabled',true).val('Saving'); seems to make things work.

Any reasons for this occuring?

A: 

It seems that you cannot modify a control disabled...

but maybe doing this should solve the problem:

$('#save_button').click(function() {
      $(this).val('Saving');
      $(this).attr('disabled',true);

      $('#new_record_form').ajaxForm({
        url: '/',
        type: "POST",
        dataType: "json",
        beforeSubmit: function(){ alert('Boo!'); },
        success: function(){ alert('Hello!'); }
      });
});
Pitming
Thanks but doesnt fix the issue with not working in other browsers...
schone
+1  A: 

I usually write $(accessor).attr("disabled", "disabled"); which results in HTML that looks like <... disabled="disabled" .../> being produced. I didn't know that you could use your syntax. Can you try this, and see if it works?

To remove the attribute, I use $(accessor).removeAttr("disabled");.

Jarrett Meyer
`true` is the more appropriate value. jQuery's `attr()` changes JavaScript/DOM properties, not HTML attributes (much though jQuery tries to paper over the differences). `disabled` is a boolean property. Setting it to `"disabled"` also works because non-empty strings coerce to `true` in a boolean context.
bobince
+1  A: 

When a html input is 'disabled', its not supposed to be able to send input. Try changing the property to 'readonly' instead.

txyoji