konithomimo
02-18-2005, 10:14 PM
How can I make it so that when a page loads one of the buttons on it is disabled for 15 seconds?
|
Click to See Complete Forum and Search --> : Button Disable konithomimo 02-18-2005, 10:14 PM How can I make it so that when a page loads one of the buttons on it is disabled for 15 seconds? phpnovice 02-18-2005, 11:24 PM Requires JavaScript -- which the maggots will now jump in here and criticize me for even speaking its name. They will also criticize just about everything else I post here but, I'll forewarn everyone that I don't post complete W3C solutions or give a rat's ass about accessibility considerations in these forums. I post just enough code to provide a solution and leave it up to the OP to handle the rest. ;-b <body onload="javascript: document.getElementById('disButton').disabled=true; window.setTimeout('enaButton()',15000); return true;"> <button id="disButton" ...>button text</button> </body> With the above, you'll need this JavaScript function: function enaButton() { document.getElementById('disButton').disabled=false; } konithomimo 02-18-2005, 11:54 PM I tried your code, but it didnt work. Here is how I implemented it...im pretty sure that it is right... <HTML> <HEAD><LINK rel="stylesheet" href="style.css" type="text/css"> <TITLE> My Site </TITLE> <script language="javascript"> function enaButton() { document.getElementById("thisbutton").disabled=false; } </script> </HEAD> <body bgcolor="#FFDFCE" text=black onload="javascript:document.getElementById("thisbutton").disabled=true; window.setTimeout("enaButton()",15000); return true;"> <center><font style="font-family:times,arial,verdana; font-size:18pt;"> Text written in here... <button id="thisbutton" onClick="parent.location='nextpage.html'"> Click Here To Enter </button> </center></font> </body> </html> I also tried it like this: <HTML> <HEAD><LINK rel="stylesheet" href="style.css" type="text/css"> <TITLE> My Site </TITLE> <script language="javascript"> function enaButton() { document.getElementById("thisbutton").disabled=false; } </script> </HEAD> <body bgcolor="#FFDFCE" text=black onload="javascript:document.getElementById("thisbutton").disabled=true; window.setTimeout("enaButton()",15000); return true;"> <form> <center><font style="font-family:times,arial,verdana; font-size:18pt;">Text Written Here</font></center> <p><center><font size=4>More Text here <br> <br><input type="button" id="thisbutton" value="Click Here To Enter" onClick="parent.location='nextpage.html'"> <br> </center></font> </p> </form> </body> </html> Of course though, that didnt work. Im sure that I am making a simple mistake. Could you please tell me what it is. I also tried moving the javascript around, but of course that didnt help any. The button will work just fine, but it never becomes disabled. :( Stephen Philbin 02-19-2005, 01:15 AM disabled="disabled" will make something unconditionally disabled, but javascript/DOM can disable something that was previously enabled. However you must accept the fact that your javascript is all but pointless and process your form as if you had never implemented any javascript. If not, you might as well stick a big marker proclaiming "Teh securitee hole are heer!". phpnovice 02-19-2005, 08:56 AM Originally posted by konithomimo I tried your code, but it didnt work. Here is how I implemented it...im pretty sure that it is right... ...snip... Im sure that I am making a simple mistake. Could you please tell me what it is... You didn't implement it as I supplied it to you. The simple mistake you made was to change the single quotes I supplied to double quotes instead. This is in the onload event of the BODY tag. If you had error reporting turned on, in your browser, it would have told you this. Also, you changed the id of the button as I supplied it. Though you should be able to change the names to suit your tastes, I'd recommend NOT starting such names with a JavaScript keyword like "this" or "new". Sometimes JavaScript can get confused over such things. This also probably applies more to the HTML name attribute than the id attribute. However, it is still a good programming practice to be consistent across the board. konithomimo 02-19-2005, 02:30 PM I actually had it with the single quotes (parenthesis) in my code. I just typed it wrong when I was replying to your post. Either way, I found a much easier way to do it. Thanks anyway. phpnovice 02-19-2005, 02:39 PM Note that the code I supplied was tested and working (in IE6, NS7.2, and Firefox 1.0) when I supplied it. There is only one way that it could be done "easier". However, that method is less "accessible" than what I supplied. But, have it your way. ;-) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |