views:

29

answers:

2

I have a form that on action: action="javascript:DoWallInsert($idf );"..

Now on this form i have this submit button. I want onclick that it should be disabled, and then enabled again on success (the ajax call inside the function).

<input name="submit" type="submit" id="submit" value="Send">
function DoWallInsert(BuID, uID){
       $('#submit').attr('disabled', true);
  var wrapperId = '#wall_insert';
    $.ajax({ 
       type: "POST",
       url: "misc/insertWall.php",
    data: {
    value: 'y',
    BuID : BuID,
    uID : uID,
    message : $('#message').val() 
    },
       success: function(msg){
$('#submit').attr('disabled', false);
     $(wrapperId).prepend(msg);
     $(wrapperId).children().first().slideDown('slow');
     $('#message').val("");
        }
     });
}

I tried this, but it doesnt work

A: 

To enable a button:

   // $('#submit').attr('enabled', true);  //incorrect
   $('#submit').removeAttr('disabled');
   //or $('#submit').attr('disabled', false);
Danny Chen
it doesnt disable my button, thats where it goes wrong
Johnson
+1  A: 

You need to remove the disabled attribute you added earlier (there is no enabled attribute), so replace this:

$('#submit').attr('enabled', true);

With this:

$('#submit').attr('disabled', false);
Nick Craver
Ok fixed, where i had the enable attribute in the success i now have this disables false. But it still doesnt disable the button and enable it..
Johnson
@user457827 - Do you have *multiple* elements with `id="submit"` by chance?
Nick Craver
Yes could be that. Should i call it something else than submit? will my form still work then?
Johnson
@user457827 - If you have multiple elements with the same ID you'll have issues (*just* like this). It's best to change them and give it (and whatever other elements are currently using it as well) a unique ID.
Nick Craver