Before I perform some json and disable a button, I simply want to enable other buttons that may have been previously disabled. I think it’s related to callbacks which I apparently still don’t get. In the code below, the clicked button does not become disabled prior to running the getJSON.
$(".btnUseProduct").live("click", function(e) {
var clickedId = $(this).attr('id');
var provisioning_id = clickedId.split("^")[0];
var entity_id = clickedId.split("^")[1];
var entity = clickedId.split("^")[2];
showUseButtons(function(){
$(this).attr({'disabled':'disabled','value':'Used'}); //doesn't work
$.getJSON("/chinabuy-new/cfcs/services.cfc?method=update_provisioning&returnformat=json&queryformat=column",{"provisioning_id":provisioning_id,"entity_id":entity_id},function(res,code){
});
});
e.preventDefault();
});
function showUseButtons() {
$(".btnUseProduct").each(function(e) {
$(this).attr({'disabled':'disabled','value':'Used'});
});
}
A callback is a function you pass to another function. That other function you pass it to must call it – otherwise it’s useless.
Above, you are passing a function to
showUseButtons– but that function just ignores it. It won’t be called so whatever you put in there won’t do anything.Perhaps you meant something like the following?
Further, inside a function the context changes (i.e. the value of
thisis different). So you’ll need to alter your code somewhat as well: