Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  27] [ 6]  / answers: 1 / hits: 16449  / 16 Years ago, mon, march 9, 2009, 12:00:00

If I have a button that sets off a jquery script is there a way to make sure the button is inactive until the script completes?


More From » jquery

 Answers
117

Somewhere at the beginning of your script (probably on the button's click event), set the button's disabled attribute to true:



$(#mybutton).attr(disabled, true);


Then, when complete, remove that attribute:



$(#mybutton).removeAttr(disabled);


EDIT:



If you want to get (slightly) fancy, change the text of the button while you're doing the work. If it's an image button, you can change the src to a friendly please wait message. Here's an example of the button text version:



$(#mybutton).click(function() {
var origVal = $(this).attr(value);

$(this).attr(value, Please wait...);
$(this).attr(disabled, true);

//Do your processing.

$(this).removeAttr(disabled);
$(this).attr(value, origVal);
});

[#99876] Monday, March 2, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briza

Total Points: 259
Total Questions: 94
Total Answers: 101

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
;