Posted By

sekihin on 04/28/09


Tagged

javascript disable


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

lfx
Vordreller


Disable button on Load


 / Published in: JavaScript
 

  1. <input type = "button" name = "but1" id = "but1" value = "Click Me" disabled = false>
  2.  
  3. <script type = "text/javascript">
  4.  
  5. var tim; // global variable
  6. function disableCancel() {
  7. tim = setTimeout(disableContinue, 2000); // 2 seconds delay
  8. }
  9.  
  10. function disableContinue() {
  11. document.getElementById("but1").disabled = true;
  12. window.clearTimeout(tim);
  13. }
  14.  
  15. disableCancel();
  16.  
  17. // Multiple onload function created by: Simon Willison
  18. // http://simonwillison.net/2004/May/26/addLoadEvent/
  19. function addLoadEvent(func) {
  20. var oldonload = window.onload;
  21. if (typeof window.onload != 'function') {
  22. window.onload = func;
  23. } else {
  24. window.onload = function() {
  25. if (oldonload) {
  26. oldonload();
  27. }
  28. func();
  29. }
  30. }
  31. }
  32.  
  33. addLoadEvent(function() {
  34. disableField();
  35. });
  36.  
  37. </script>

Report this snippet  

You need to login to post a comment.