I have a form with a few dropdowns and a textbox. If the page had an issue and a refresh is performed, I want to repopulate the fields with the values originally entered. How would I save these values to memory. I assume I would create global variables with javascript and add the onchange event to the fields, however, I am stucking in getting this to perform.
How to store the values of fields into memory?
Collapse
X
-
Tags: None
-
Eventually HTML5 is supposed to have client side storage but not all browsers have this implemented yet.
So, as Rabbit suggested, use cookies for now...or store the original values on the server...or submit the current values to the server and "fix the problem" upon refreshing.Comment
-
My problem is now a little more complex. I wont be able to store the values on the server. Any ideas or pointers to how to create a cookie to store the value of a text input and a dropdown selected value/index?Comment
-
You set the document.cookie property to create a cookie(s). You parse it to retrieve the cookie.
Code:// Set a cookie document.cookie = "username=Rabbit;" // Read a cookie document.cookie.substr(document.cookie.indexOf("=")+1);
Comment
-
You set the document.cookie property to create a cookie(s). You parse it to retrieve the cookie.
Code:// Set a cookie document.cookie = "username=Rabbit;" // Read a cookie document.cookie.substr(document.cookie.indexOf("=")+1);
Code:function setCookie(cookieName, value) { var expiration = new Date(); expiration.setDate(expiration.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+expiration.toUTCString()); document.cookie= cookieName + "=" + c_value; }
Code:function getCookie(cookieName) { for (i=0; i< theCookies.length; i++) { x=theCookies[i].substr(0,theCookies[i].indexOf("=")); y=theCookies[i].substr(theCookies[i].indexOf("=")+1); if(x == cookieName) { return unescape(y) } }
Code:setCookie("Department", document.getElementById("Department").value); concatenateFields();---works document.getElementById("ShowMoreTasksButton").click();---works document.getElementById("Department").value = getCookie("Department").value; --the element does not get the value inserted
Comment
-
Comment
Comment