|
INTERVIEW QUESTIONS
WEB
JAVA SCRIPT
DETAILS
Question: How to getting values from cookies to set widgets?
Answer: 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(); }
|
|
|
Category |
Java Script Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9505 users |
Added on |
9/21/2014 |
Views |
67423 |
Rate it! |
|
|
Question:
How to getting values from cookies to set widgets?
Answer:
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(); } 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 setting a cookie with the contents of a textbox?
|
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
|