There is no such thing as "Document.GetelementbyId". There is however a:
document.getElementById
Upper and lower case letters are almost always critical in javascript.
That said, the getCookie function in your post is serviceable. Except that it has an extra trailing } after it, which I've marked in red in your post. It should be:
Code:
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
alert(c_value);
return c_value;
}
But there is a more efficient way:
Code:
function getCookie(n){ // getCookie takes (n) - the name of the cookie
var c = document.cookie.match('(^|;)\x20*' + n + '=([^;]*)');
return c? unescape(c[2]) : null;
}
Bookmarks