PDA

View Full Version : disable button



urgido
08-23-2006, 05:42 AM
I'm looking like this script: http://dynamicdrive.com/dynamicindex11/submitonce.htm

I want to disable a button for the next 6 hours.
Reason: I want the code for special section of my page called "lost passwords".

Regards

ddadmin
08-23-2006, 05:53 AM
Hmm I'm not 100% certain I understand, but to disable a submit button, you merely use the "disabled" attribute inside the tag:


<input id="abutton" type="submit" disabled="disabled" value="submit" />

Alternately, in your script, you can do:


document.getElementById("abutton").disabled=true //disable button
document.getElementById("abutton").disabled=false //enable button

jscheuer1
08-23-2006, 06:03 AM
This could be done with javascript, theoretically. I am assuming you want any given user, once they have used this button, to not be able to do so again for 6 hours.

Here is the scenario:

1 ) The page loads, javascript checks to see if they have a cookie that tells it to disable the button, if so, the button is disabled, if not -
2 ) They click the button.
3 ) Javascript drops said cookie on their computer, setting it to expire in 6 hours.

This is all well and good if javascript is enabled and the user doesn't clear their cookies. Many users automatically clear cookies after each session, some anti-spyware programs clear them virtually the moment that they are set. Any user may elect to manually clear cookies at any time.

The bottom line being that if this is at all critical or meant as a secure method for disallowing repeated use of this button, you should find another method. Server side code would be well suited to this. Something like PHP or ASP.