acidglitter Posted May 28, 2008 Share Posted May 28, 2008 on a site i'm making, you click a button that calls ajax to add that product to your shopping bag. it takes a little while to load though so i'm worried someone will click the button, then while its still loading, click it again and call the function all over again. is there a way you can prevent the function from starting if it has already started? (if that makes sense ) Quote Link to comment Share on other sites More sharing options...
haku Posted May 28, 2008 Share Posted May 28, 2008 You can set the button to disabled at the start of your function. I believe you do it like this: this.disabled = true If this is the first command in your onclick script, the button will be disabled for the rest of the script. If you want the button to be usable again at some point, you will have to use: this.disabled = false in order to re-enable it. Quote Link to comment Share on other sites More sharing options...
acidglitter Posted June 2, 2008 Author Share Posted June 2, 2008 how would you be able to do that with a text link? Quote Link to comment Share on other sites More sharing options...
zohab Posted June 3, 2008 Share Posted June 3, 2008 hi when u call ajax at that time disable the submit button till u get request from server with the help of ajax when ajax is working /processing the request submit button will be disabled as soon as ajax processing is over submit button will be active. Quote Link to comment Share on other sites More sharing options...
acidglitter Posted June 3, 2008 Author Share Posted June 3, 2008 thanks for the reply but that doesn't answer my new question.. how can you disable a text link? Quote Link to comment Share on other sites More sharing options...
haku Posted June 4, 2008 Share Posted June 4, 2008 I can only think of a hack of sorts in order to disable a text link. Its not the greatest solution, and maybe someone else can come up with something better than this, but you could do this: - When the script is executed, immediately create an element with a unique ID name and a display set to none, and append it somewhere on the page - At the end of your script, remove this appended element - At the very start of the script (even before step 1), check to see if the element with said unique ID exists. If it does, then return false (which will exit the script). By doing this the script will not run if clicked a second time, as it has not finished running the first time. However, you are appending unneeded elements to your page which is why its not the greatest solution. I've never done this, but it will work except for the situation where someone manages to click the link for as second time before the element is appended on the page. But this appending should be too fast for someone to be able to do that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.