|
INTERVIEW QUESTIONS
WEB
JAVA SCRIPT
DETAILS
Question: How to setting a cookie with the contents of a textbox?
Answer: 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()" />
|
|
|
Category |
Java Script Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8854 users |
Added on |
9/21/2014 |
Views |
67030 |
Rate it! |
|
|
Question:
How to setting a cookie with the contents of a textbox?
Answer:
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()" /> Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How to open a window with no toolbar, but with the location object?
|
View Answer
|
|
How to create an input box?
|
View Answer
|
|
How to create a confirmation box?
|
View Answer
|
|
How to create a popup warning box?
|
View Answer
|
|
Explain unescape() and escape() in JavaScript?
|
View Answer
|
|
How to have the status line update when the mouse goes over a link (The support of the status line is sporadic)?
|
View Answer
|
|
How to have an element invoke a JavaScript on selection, instead of going to a new URL?
|
View Answer
|
|
How to Add new elements dynamically?
|
View Answer
|
|
To write messages to the screen without using "document.write()"?
|
View Answer
|
|
How to disable an HTML object?
|
View Answer
|
|
How to find radio button selection when a form is submitted?
|
View Answer
|
|
How to find the selected radio button immediately using the 'this' variable?
|
View Answer
|
|
What is === operator?
|
View Answer
|
|
What are undefined and undeclared variables?
|
View Answer
|
|
Does JavaScript have the concept level scope?
|
View Answer
|
|
What is variable typing in JavaScript?
|
View Answer
|
|
What is the difference between undefined value and null value?
|
View Answer
|
|
What does undefined value mean in JavaScript?
|
View Answer
|
|
How to select an element by id and swapping an image?
|
View Answer
|
|
To set all checkboxes to true using JavaScript?
|
View Answer
|