home *** CD-ROM | disk | FTP | other *** search
/ PC User 2005 May / CD / PCU0505CD.iso / software / full / coffecup / files / html2005.exe / %MAINDIR% / Javascript / Random-Background.xml < prev    next >
Encoding:
Text File  |  2005-02-16  |  2.2 KB  |  99 lines

  1. <ccResource>
  2.   <ccTitle>
  3. Random Background
  4.   </ccTitle>
  5.   <ccCategory>
  6. Browser
  7.   </ccCategory>
  8.   <ccDescription>
  9. Get a random background color with the touch of a button. 
  10.  </ccDescription>
  11.   <ccInstructions>
  12.    1.  Add the designated script to the HEAD of your HTML document
  13.    2.  Place the last script into the BODY of your HTML document
  14.     </ccInstructions>
  15.   <ccHeadContent>
  16.   
  17.   </ccHeadContent>
  18.   <ccBodyContent>
  19. <SCRIPT LANGUAGE="JavaScript">
  20.  
  21.  
  22. <!-- Begin
  23. function backcolor(form) {
  24. temp = ""
  25. for (var i = 0; i < 16; i++) {
  26. temp = form.color[i].value
  27. if (form.color[i].checked){ document.bgColor = temp }
  28.    }
  29. }
  30. function randombackground() {
  31. document.bgColor = getColor()
  32. }
  33. function getColor(){
  34. currentdate = new Date()
  35. backgroundcolor = currentdate.getSeconds()
  36. if (backgroundcolor > 44)
  37. backgroundcolor = backgroundcolor - 45
  38. else if (backgroundcolor > 29)
  39. backgroundcolor = backgroundcolor - 30
  40. else if (backgroundcolor > 15)
  41. backgroundcolor = backgroundcolor - 16
  42. if (backgroundcolor == 0 )
  43. return "olive";
  44. else if (backgroundcolor == 1 )
  45. return "teal";
  46. else if (backgroundcolor == 2 )
  47. return "red";
  48. else if (backgroundcolor == 3 )
  49. return "blue";
  50. else if (backgroundcolor == 4 )
  51. return "maroon";
  52. else if (backgroundcolor == 5 )
  53. return "navy";
  54. else if (backgroundcolor == 6 )
  55. return "lime";
  56. else if (backgroundcolor == 7 )
  57. return "fuschia";
  58. else if (backgroundcolor == 8 )
  59. return "green";
  60. else if (backgroundcolor == 9 )
  61. return "purple";
  62. else if (backgroundcolor == 10 )
  63. return "gray";
  64. else if (backgroundcolor == 11 )
  65. return "yellow";
  66. else if (backgroundcolor == 12 )
  67. return "aqua";
  68. else if (backgroundcolor == 13 )
  69. return "black";
  70. else if (backgroundcolor == 14 )
  71. return "white";
  72. else if (backgroundcolor == 15 )
  73. return "silver";
  74. }
  75. // End -->
  76. </SCRIPT>
  77.  
  78. <!-- STEP TWO:  Put this form in the BODY of the HTML document  -->
  79.  
  80. <BODY>
  81.  
  82. <CENTER>
  83. <FORM>
  84. <input type="button" value="Get Another Random Background" onClick="randombackground()">
  85. </FORM>
  86. </CENTER>
  87.  
  88.  
  89.   </ccBodyContent>
  90.   <ccElementContent>
  91.   
  92.    <ccElementName></ccElementName>
  93.    <ccElementAction></ccElementAction>
  94.    
  95.   </ccElementContent>
  96.   <ccExtraData>
  97.  
  98.   </ccExtraData>
  99. </ccResource>