943,793 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jan 20th, 2009
0

Re: reset list box is not working javascript

this is the code that i got from you

give it a try

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2.  
  3. <head>
  4.  
  5. <script type="text/javascript">
  6.  
  7. function bakeCookie(name,value){
  8. args=arguments;argc=args.length;
  9. expires=(argc>2) ? args[2] : null;
  10. path=(argc>3) ? args[3] : null;
  11. domain=(argc>4) ? args[4] : null;
  12. secure=(argc>5) ? args[5] : false;
  13. expDate=new Date();day=24*60*60*1000;
  14. if(expires){expDate.setTime(expDate.getTime()+expires*day);}
  15. document.cookie=name+"="+escape(value)+
  16. ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+
  17. ((path===null) ? "" : ("; path="+path))+
  18. ((domain===null) ? "" : ("; domain="+domain))+
  19. ((secure===true) ? "; secure" : "");
  20. }
  21.  
  22.  
  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.  
  41. /* Additional function added for deleting cookies */
  42.  
  43. function deleteCookie(name) {
  44. document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT' + '; path='; }
  45.  
  46. function newColor(entry,areaID){ // use DOM method
  47. bakeCookie("colorSet",entry,7); // save for a week
  48. if (!areaID){areaID="body";} // default to whole body
  49. document.getElementById(areaID).style.background=entry;
  50. }
  51.  
  52. function newFont(entry,areaID){ // use DOM method
  53. bakeCookie("fontSet",entry,7); // save for a week
  54. if (!areaID){areaID="body";} // default to whole body
  55. document.getElementById(areaID).style.fontFamily=entry;
  56. }
  57.  
  58. function isColorSet(areaID) { // points at color element
  59.  
  60. colorSet=null;
  61. if(!(colorSet=eatCookie("colorSet"))){colorSet=null;}
  62. if(colorSet!==null){newColor(colorSet,areaID);}
  63.  
  64. fontSet=null;
  65. if(!(fontSet=eatCookie("fontSet"))){fontSet=null;}
  66. if(fontSet!==null){newFont(fontSet,areaID);}
  67.  
  68. }
  69.  
  70. function resetLists(){
  71. document.forms[0].select1.options[1].selected = true;
  72. document.forms[0].select2.options[1].selected = true;
  73.  
  74. if ((document.forms[0].select1.selectedIndex == 1) && (document.forms[0].select2.selectedIndex == 1)) {
  75. deleteCookie('colorSet');
  76. deleteCookie('fontSet');
  77. document.body.setAttribute('style','font:normal 80% Arial, sans-serif;background:#fff;color:#000;'); }
  78. }
  79. </script>
  80.  
  81.  
  82. </head>
  83.  
  84. <!--Start the html body-->
  85. <body id="body" onload="isColorSet()">
  86. <form action="" onsubmit="return false;">
  87.  
  88. <select name="select1" onchange="newColor(this.value);">
  89. <option value="">Background Color</option>
  90. <option value="Blue">Blue</option>
  91. <option value="Green">Green</option>
  92. <option value="Orange">Orange</option>
  93. <option value="Red">Red</option>
  94. <option value="Violet">Violet</option>
  95. <option value="Yellow">Yellow</option>
  96. </select>
  97.  
  98. <select name="select2" onchange="newFont(this.value);">
  99. <option value="">Font Family</option>
  100. <option value="Arial">Arial</option>
  101. <option value="Helvetica">Helvetica</option>
  102. <option value="Tahoma">Tahoma</option>
  103. <option value="Times New Roman">Times New Roman</option>
  104. <option value="Verdana">Verdana</option>
  105. </select>
  106.  
  107.  
  108.  
  109. </br>
  110. </br>
  111.  
  112. BLA BLA BLA BLA BLABLA BLA BLA BLA
  113.  
  114. </form>
  115.  
  116. <button onclick="resetLists()">Reset</button>
  117.  
  118. </body>
  119.  
  120. </html>

this is a better explanation than my english lol

it shows u what problem that i have

reset is not working properly
Reputation Points: 10
Solved Threads: 0
Light Poster
ayi_102 is offline Offline
27 posts
since Nov 2008
Jan 20th, 2009
0

Re: reset list box is not working javascript

Just create another file, that say's (testpage.html) and bring up the codes in here into that document.
This is a working script tested and working in IE and Opera--

javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6.  
  7. <script type="text/javascript">
  8. <!--
  9. function bakeCookie(name,value){
  10. args=arguments;argc=args.length;
  11. expires=(argc>2) ? args[2] : null;
  12. path=(argc>3) ? args[3] : null;
  13. domain=(argc>4) ? args[4] : null;
  14. secure=(argc>5) ? args[5] : false;
  15. expDate=new Date();day=24*60*60*1000;
  16. if(expires){expDate.setTime(expDate.getTime()+expires*day);}
  17. document.cookie=name+"="+escape(value)+
  18. ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+
  19. ((path===null) ? "" : ("; path="+path))+
  20. ((domain===null) ? "" : ("; domain="+domain))+
  21. ((secure===true) ? "; secure" : "");
  22. }
  23.  
  24.  
  25. function eatCookieVal(name) {
  26. endstr=document.cookie.indexOf(";",name);
  27. if(endstr===-1) {endstr=document.cookie.length;}
  28. return unescape(document.cookie.substring(name,endstr));
  29. }
  30. function eatCookie(name) {
  31. arg=name+"="; alen=arg.length;
  32. clen=document.cookie.length; i=0;
  33. while (i<clen) {
  34. j=i+alen;
  35. if(document.cookie.substring(i,j)===arg){
  36. return eatCookieVal(j);
  37. }
  38. i=document.cookie.indexOf(" ",i)+1;
  39. if(i===0){break;}
  40. }
  41. }
  42.  
  43. /* Additional function added for deleting cookies */
  44.  
  45. function deleteCookie(name) {
  46. document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT' + '; path='; }
  47.  
  48. function newColor(entry,areaID){ // use DOM method
  49. bakeCookie("colorSet",entry,7); // save for a week
  50. if (!areaID){areaID="body";} // default to whole body
  51. document.getElementById(areaID).style.background=entry;
  52. }
  53.  
  54. function newFont(entry,areaID){ // use DOM method
  55. bakeCookie("fontSet",entry,7); // save for a week
  56. if (!areaID){areaID="body";} // default to whole body
  57. document.getElementById(areaID).style.fontFamily=entry;
  58. }
  59.  
  60. function isColorSet(areaID) { // points at color element
  61.  
  62. colorSet=null;
  63. if(!(colorSet=eatCookie("colorSet"))){colorSet=null;}
  64. if(colorSet!==null){newColor2(colorSet,areaID);}
  65.  
  66. fontSet=null;
  67. if(!(fontSet=eatCookie("fontSet"))){fontSet=null;}
  68. if(fontSet!==null){newFont(fontSet,areaID);}
  69.  
  70. }
  71.  
  72. function resetLists(){
  73. document.forms[0].select1.selectedIndex = 0;
  74. document.forms[0].select2.selectedIndex = 0;
  75. if ((document.forms[0].select1.selectedIndex == 0) && (document.forms[0].select2.selectedIndex == 0)) {
  76. deleteCookie('colorSet');
  77. deleteCookie('fontSet');
  78. document.body.style.backgroundColor = '#FFF';
  79. document.body.style.color = '#000';
  80. document.body.style.fontSize = '80%';
  81. alert(document.cookie); }
  82.  
  83. }
  84. //-->
  85. </script>
  86. </head>
  87. <!--Start the html body-->
  88. <body id="body" onload="isColorSet()">
  89. <h3>Sample</h3>
  90. <form action="#" onsubmit="return false;">
  91.  
  92. <select name="select1" onchange="newColor(this.value);">
  93. <option value="">Background Color</option>
  94. <option value="Blue">Blue</option>
  95. <option value="Green">Green</option>
  96. <option value="Orange">Orange</option>
  97. <option value="Red">Red</option>
  98. <option value="Violet">Violet</option>
  99. <option value="Yellow">Yellow</option>
  100. </select>
  101.  
  102. <select name="select2" onchange="newFont(this.value);">
  103. <option value="">Font Family</option>
  104. <option value="Arial">Arial</option>
  105. <option value="Helvetica">Helvetica</option>
  106. <option value="Tahoma">Tahoma</option>
  107. <option value="Times New Roman">Times New Roman</option>
  108. <option value="Verdana">Verdana</option>
  109. </select>
  110.  
  111.  
  112.  
  113. </br>
  114. </br>
  115.  
  116. BLA BLA BLA BLA BLABLA BLA BLA BLA
  117.  
  118. </form>
  119.  
  120. <button onclick="resetLists()">Reset</button>
  121.  
  122. </body>
  123.  
  124. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Jan 20th, 2009
0

Re: reset list box is not working javascript

If this doesnt work. Then i suggest that you try things with PHP--its more precise and reliable than using cookies...
Last edited by essential; Jan 20th, 2009 at 6:57 am.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Jan 21st, 2009
0

Re: reset list box is not working javascript

thank you for the help essential

regards,

ayi
Reputation Points: 10
Solved Threads: 0
Light Poster
ayi_102 is offline Offline
27 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: need to include a listbox from one html page to another
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Geolocation API





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC