Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How to set a cookie with the contents of a textbox ?
How to set a cookie with the contents of a textbox ?
✍: Guest
Values stored in cookies may not have semicolons, commas, or spaces.
You should use the handy "escape()" function to encode the values,
and "unescape()" to retrieve them.
//Sets cookie of current value for myTextBox
function TextBoxOnchange() {
var myBox = window.document.getElementById(myTextBox");
document.cookie = "myTextBox="+ escape(myBox.value) + getExpirationString();
}
//return a string like ";expires=Thu, 5 Jan 2006 16:07:52 UTC"
function getExpirationString() {
var exp = new Date();
var threemonths = exp.getTime()+(120*24*60*60*1000);
exp.setTime(threemonths);
return ";expires="+exp.toGMTString();
}
This is called from the event handler in the HTML.
<input name="myTextBox" type="text" id="myTextBox"
onchange="javascript:TextBoxOnchange()" />
2024-03-11, 5497👍, 4💬
Popular Posts:
How To Increment Dates by 1? - Oracle DBA FAQ - Understanding SQL Basics If you have a date, and you...
What is the difference between "printf(...)" and "sprintf(...)"? sprintf(...) writes data to the cha...
How To Control Padding Spaces within a Table Cell? - XHTML 1.0 Tutorials - Understanding Tables and ...
How can you implement MVC pattern in ASP.NET? The main purpose using MVC pattern is to decouple the ...
How do I force the Dispose method to be called automatically, as clients can forget to call Dispose ...