This is a discussion on How to getting values from cookies to set widgets? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; How to getting values from cookies to set widgets?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| function getCookieData(labelName) { //from Danny Goodman var labelLen = labelName.length; // read cookie property only once for speed var cookieData = document.cookie; var cLen = cookieData.length; var i = 0; var cEnd; while (i < cLen) { var j = i + labelLen; if (cookieData.substring(i,j) == labelName) { cEnd = cookieData.indexOf(";",j); if (cEnd == -1) { cEnd = cookieData.length; } return unescape(cookieData.substring(j+1, cEnd)); } i++; } return ""; } //init() is called from the body tag onload function. function init() { setValueFromCookie("brand"); setValueFromCookie("market"); setValueFromCookie("measure"); } function setValueFromCookie(widget) { if( getCookieData(widget) != "") { document.getElementById(widget).value = getCookieData(widget); } } //if you name your cookies the widget ID, you can use the following helper function function setCookie(widget) { document.cookie = widget + "=" + escape(document.getElementById(widget).value) + getExpirationString(); } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cookies | nhoj | Java Server Pages (JSP) | 4 | 09-28-2008 11:32 PM |
| Cookies before start using in php | vigneshgets | PHP Programming | 1 | 01-18-2008 03:18 AM |
| Creating Cookies | pranky | HTML, CSS and Javascript Coding Techniques | 2 | 11-21-2007 04:02 AM |
| Cookies | ragavraj | PHP Programming | 4 | 11-01-2007 11:48 AM |
| Store and Retrieve the values in cookies in ASP.NET | oxygen | ASP and ASP.NET Programming | 0 | 07-19-2007 11:23 PM |