View Single Post
Join Date: Nov 2008
Posts: 27
Reputation: ayi_102 is an unknown quantity at this point 
Solved Threads: 0
ayi_102 ayi_102 is offline Offline
Light Poster

Re: save and load font and background setting using cookies

 
0
  #6
Jan 15th, 2009
This one is working example

but i want to change it into listbox instead of radio button

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2.  
  3. <head>
  4.  
  5. <script type="text/javascript">
  6. function bakeCookie(name,value){
  7. args=arguments;argc=args.length;
  8. expires=(argc>2) ? args[2] : null;
  9. path=(argc>3) ? args[3] : null;
  10. domain=(argc>4) ? args[4] : null;
  11. secure=(argc>5) ? args[5] : false;
  12. expDate=new Date();day=24*60*60*1000;
  13. if(expires){expDate.setTime(expDate.getTime()+expires*day);}
  14. document.cookie=name+"="+escape(value)+
  15. ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+
  16. ((path===null) ? "" : ("; path="+path))+
  17. ((domain===null) ? "" : ("; domain="+domain))+
  18. ((secure===true) ? "; secure" : "");
  19. }
  20. </script>
  21.  
  22. <script type="text/javascript">
  23. function eatCookieVal(name) {
  24. endstr=document.cookie.indexOf(";",name);
  25. if(endstr===-1) {endstr=document.cookie.length;}
  26. return unescape(document.cookie.substring(name,endstr));
  27. }
  28. function eatCookie(name) {
  29. arg=name+"="; alen=arg.length;
  30. clen=document.cookie.length; i=0;
  31. while (i<clen) {
  32. j=i+alen;
  33. if(document.cookie.substring(i,j)===arg){
  34. return eatCookieVal(j);
  35. }
  36. i=document.cookie.indexOf(" ",i)+1;
  37. if(i===0){break;}
  38. }
  39. }
  40. </script>
  41.  
  42. <script type="text/javascript">
  43. function newColor2(entry,areaID){ // use DOM method
  44. bakeCookie("colorSet",entry,7); // save for a week
  45. if (!areaID){areaID="body";} // default to whole body
  46. document.getElementById(areaID).style.background=entry;
  47. }
  48. </script>
  49.  
  50. <script type="text/javascript">
  51. function newFont(entry,areaID){ // use DOM method
  52. bakeCookie("fontSet",entry,7); // save for a week
  53. if (!areaID){areaID="body";} // default to whole body
  54. document.getElementById(areaID).style.fontFamily=entry;
  55. }
  56. </script>
  57.  
  58. <script type="text/javascript">
  59. function isColorSet(areaID) { // points at color element
  60.  
  61. colorSet=null;
  62. if(!(colorSet=eatCookie("colorSet"))){colorSet=null;}
  63. if(colorSet!==null){newColor2(colorSet,areaID);}
  64.  
  65. fontSet=null;
  66. if(!(fontSet=eatCookie("fontSet"))){fontSet=null;}
  67. if(fontSet!==null){newFont(fontSet,areaID);}
  68.  
  69. }
  70. </script>
  71.  
  72. </head>
  73.  
  74. <!--Start the html body-->
  75. <body id="body" onload="isColorSet()">
  76. <form action="" onsubmit="return false;">
  77.  
  78. <fieldset>
  79. <legend>Radio Background Color Selector</legend>
  80. <label>Aquamarine:<input name="radCol" type="radio"
  81. onclick="newColor2('Aquamarine');"/></label>
  82. <label>Burlywood:<input name="radCol" type="radio"
  83. onclick="newColor2('Burlywood');"/></label>
  84. <label>Floralwhite:<input name="radCol" type="radio"
  85. onclick="newColor2('Floralwhite');"/></label><br>
  86. <label>Goldenrod:<input name="radCol" type="radio"
  87. onclick="newColor2('Goldenrod');"/></label>
  88. <label>Peachpuff:<input name="radCol" type="radio"
  89. onclick="newColor2('Peachpuff');"/></label>
  90. </fieldset>
  91.  
  92. </br>
  93. </br>
  94.  
  95. <fieldset>
  96. <legend>Radio Background Font Selector</legend>
  97. <label>Verdana:<input name="radCol" type="radio"
  98. onclick="newFont('Verdana');"/></label>
  99. <label>Arial:<input name="radCol" type="radio"
  100. onclick="newFont('Arial');"/></label>
  101. <label>Tahoma:<input name="radCol" type="radio"
  102. onclick="newFont('Tahoma');"/></label>
  103. </fieldset>
  104.  
  105. </br>
  106. </br>
  107.  
  108. <fieldset>
  109. <legend>Listbox Color Selector</legend>
  110. <select onchange="newColor2('body', this);">
  111. <option value="">Background Color</option>
  112. <option value="Blue">Blue</option>
  113. <option value="Green">Green</option>
  114. <option value="Orange">Orange</option>
  115. <option value="Red">Red</option>
  116. <option value="Violet">Violet</option>
  117. <option value="Yellow">Yellow</option>
  118. </select>
  119. </fieldset>
  120.  
  121. </br>
  122. </br>
  123.  
  124. BLA BLA BLA BLA BLABLA BLA BLA BLA
  125.  
  126. </form>
  127.  
  128. </body>
  129.  
  130. </html>


it works with radio button but not with listbox
i dont know how to make the listbox works

hope that someone can help me

thank you
Reply With Quote