Interview
    C#
    VB.Net
    VC++
    ASP.Net
    ADO.Net
    .Net Framework
    Silverlight
    WPF(Windows Presentation Foundation)/XAML
    WCF(Windows Communication Foundation)
    Java
    PHP
    AJAX
    Assembly
    XML
    Wireless/Mobile Development
    Cold Fusion
    MSSQL Server 2000/2005/2008/2012
    MYSQL
    DB2
    MS Access
    Java Script
    VB Script
    JQuery
    Testing
    BlackBox Testing
    WhiteBox Testing
    OOPS
    SharePoint
    ASP.NET MVC
    HTML5
    CSS/CSS3
    IIS 7
    Windows 8
    Google API
    Facebook API
    Twitter API
    Android Programming
    iPhone/iPad Programming
    Windows Phone Programming
    Json
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit Question | Search 
Report Abuse Form
Reason:    
 
Interview
Home >> Java Script >> How to setting a cookie with the contents of a textbox ?

How to setting a cookie with the contents of a textbox ?

Posted By Awadhendra Tiwari on 5/18/2011
Views: 862
Major Category: Scripting
Sub Category: Java Script
Total Answer 1
User Information Answer
• Awadhendra Tiwari
Posted Date 5/18/2011
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()" />

Report Abuse

Report Abuse Form
Reason:    
 
Total Online Users: 5127
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2014MindStick. All Rights Reserved.