| | |
reset list box is not working javascript
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 27
Reputation:
Solved Threads: 0
this is the code that i got from you
give it a try
this is a better explanation than my english lol
it shows u what problem that i have
reset is not working properly
give it a try
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function bakeCookie(name,value){ args=arguments;argc=args.length; expires=(argc>2) ? args[2] : null; path=(argc>3) ? args[3] : null; domain=(argc>4) ? args[4] : null; secure=(argc>5) ? args[5] : false; expDate=new Date();day=24*60*60*1000; if(expires){expDate.setTime(expDate.getTime()+expires*day);} document.cookie=name+"="+escape(value)+ ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+ ((path===null) ? "" : ("; path="+path))+ ((domain===null) ? "" : ("; domain="+domain))+ ((secure===true) ? "; secure" : ""); } function eatCookieVal(name) { endstr=document.cookie.indexOf(";",name); if(endstr===-1) {endstr=document.cookie.length;} return unescape(document.cookie.substring(name,endstr)); } function eatCookie(name) { arg=name+"="; alen=arg.length; clen=document.cookie.length; i=0; while (i<clen) { j=i+alen; if(document.cookie.substring(i,j)===arg){ return eatCookieVal(j); } i=document.cookie.indexOf(" ",i)+1; if(i===0){break;} } } /* Additional function added for deleting cookies */ function deleteCookie(name) { document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT' + '; path='; } function newColor(entry,areaID){ // use DOM method bakeCookie("colorSet",entry,7); // save for a week if (!areaID){areaID="body";} // default to whole body document.getElementById(areaID).style.background=entry; } function newFont(entry,areaID){ // use DOM method bakeCookie("fontSet",entry,7); // save for a week if (!areaID){areaID="body";} // default to whole body document.getElementById(areaID).style.fontFamily=entry; } function isColorSet(areaID) { // points at color element colorSet=null; if(!(colorSet=eatCookie("colorSet"))){colorSet=null;} if(colorSet!==null){newColor(colorSet,areaID);} fontSet=null; if(!(fontSet=eatCookie("fontSet"))){fontSet=null;} if(fontSet!==null){newFont(fontSet,areaID);} } function resetLists(){ document.forms[0].select1.options[1].selected = true; document.forms[0].select2.options[1].selected = true; if ((document.forms[0].select1.selectedIndex == 1) && (document.forms[0].select2.selectedIndex == 1)) { deleteCookie('colorSet'); deleteCookie('fontSet'); document.body.setAttribute('style','font:normal 80% Arial, sans-serif;background:#fff;color:#000;'); } } </script> </head> <!--Start the html body--> <body id="body" onload="isColorSet()"> <form action="" onsubmit="return false;"> <select name="select1" onchange="newColor(this.value);"> <option value="">Background Color</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Orange">Orange</option> <option value="Red">Red</option> <option value="Violet">Violet</option> <option value="Yellow">Yellow</option> </select> <select name="select2" onchange="newFont(this.value);"> <option value="">Font Family</option> <option value="Arial">Arial</option> <option value="Helvetica">Helvetica</option> <option value="Tahoma">Tahoma</option> <option value="Times New Roman">Times New Roman</option> <option value="Verdana">Verdana</option> </select> </br> </br> BLA BLA BLA BLA BLABLA BLA BLA BLA </form> <button onclick="resetLists()">Reset</button> </body> </html>
this is a better explanation than my english lol
it shows u what problem that i have
reset is not working properly
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--
This is a working script tested and working in IE and Opera--
javascript Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <script type="text/javascript"> <!-- function bakeCookie(name,value){ args=arguments;argc=args.length; expires=(argc>2) ? args[2] : null; path=(argc>3) ? args[3] : null; domain=(argc>4) ? args[4] : null; secure=(argc>5) ? args[5] : false; expDate=new Date();day=24*60*60*1000; if(expires){expDate.setTime(expDate.getTime()+expires*day);} document.cookie=name+"="+escape(value)+ ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+ ((path===null) ? "" : ("; path="+path))+ ((domain===null) ? "" : ("; domain="+domain))+ ((secure===true) ? "; secure" : ""); } function eatCookieVal(name) { endstr=document.cookie.indexOf(";",name); if(endstr===-1) {endstr=document.cookie.length;} return unescape(document.cookie.substring(name,endstr)); } function eatCookie(name) { arg=name+"="; alen=arg.length; clen=document.cookie.length; i=0; while (i<clen) { j=i+alen; if(document.cookie.substring(i,j)===arg){ return eatCookieVal(j); } i=document.cookie.indexOf(" ",i)+1; if(i===0){break;} } } /* Additional function added for deleting cookies */ function deleteCookie(name) { document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT' + '; path='; } function newColor(entry,areaID){ // use DOM method bakeCookie("colorSet",entry,7); // save for a week if (!areaID){areaID="body";} // default to whole body document.getElementById(areaID).style.background=entry; } function newFont(entry,areaID){ // use DOM method bakeCookie("fontSet",entry,7); // save for a week if (!areaID){areaID="body";} // default to whole body document.getElementById(areaID).style.fontFamily=entry; } function isColorSet(areaID) { // points at color element colorSet=null; if(!(colorSet=eatCookie("colorSet"))){colorSet=null;} if(colorSet!==null){newColor2(colorSet,areaID);} fontSet=null; if(!(fontSet=eatCookie("fontSet"))){fontSet=null;} if(fontSet!==null){newFont(fontSet,areaID);} } function resetLists(){ document.forms[0].select1.selectedIndex = 0; document.forms[0].select2.selectedIndex = 0; if ((document.forms[0].select1.selectedIndex == 0) && (document.forms[0].select2.selectedIndex == 0)) { deleteCookie('colorSet'); deleteCookie('fontSet'); document.body.style.backgroundColor = '#FFF'; document.body.style.color = '#000'; document.body.style.fontSize = '80%'; alert(document.cookie); } } //--> </script> </head> <!--Start the html body--> <body id="body" onload="isColorSet()"> <h3>Sample</h3> <form action="#" onsubmit="return false;"> <select name="select1" onchange="newColor(this.value);"> <option value="">Background Color</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Orange">Orange</option> <option value="Red">Red</option> <option value="Violet">Violet</option> <option value="Yellow">Yellow</option> </select> <select name="select2" onchange="newFont(this.value);"> <option value="">Font Family</option> <option value="Arial">Arial</option> <option value="Helvetica">Helvetica</option> <option value="Tahoma">Tahoma</option> <option value="Times New Roman">Times New Roman</option> <option value="Verdana">Verdana</option> </select> </br> </br> BLA BLA BLA BLA BLABLA BLA BLA BLA </form> <button onclick="resetLists()">Reset</button> </body> </html>
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: need to include a listbox from one html page to another
- Next Thread: Geolocation API
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta browser captchaformproblem cart checkbox child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming prototype redirect runtime safari scale scriptlets scroll search security select session shopping size software toggle unicode variables w3c web wysiwyg \n





