View Single Post
Old 12-16-2012, 03:34 PM   PM User | #1
ABorrello
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ABorrello is an unknown quantity at this point
Get cookie values

Hi,
I am new to javascript and I am trying to develop a way to filter cookies on my site.
As the user interacts with some of my site elements, I need certain cookies to change. I simply need a way to filter through my cookie list (document.cookie) to find a specific cookie name. I have this so far...

Code:
function valueget() {
var findinstr = document.cookie;
var tofindstr = document.getElementById('tofind').value;
var findresult = '';
var str_parts = findinstr.split(";");
var i = 0;
while (findresult==''||i<=str_parts.length-1) {
if (str_parts[i].substring('','=')==tofindstr) {
findresult = str_parts[i].substring('=','');
}
else {
i = i + 1;
}
}
if (findresult=='') {
alert('Could not be found');
}
else {
alert(findresult);
}
}
and the HTML code is simply

Code:
<input type="text" id="tofind">
<input type="button" value="Get Value" onclick="valueget()">
Is this the best way to find a cookie name and value, or is there an easier way.

By the way, every time I test this script, my page freezes

Any help is appreciated
ABorrello is offline   Reply With Quote