So I have a long chunk of JavaScript on my website’s administrator panel. Almost everything appears to work… until I add this function! I got it from W3Schools, which is why I’m surprised. Despite all my staring and syntax-highlighting, though, I can’t find any syntax errors or anything, so I have absolutely no idea why this is killing my script.
function getCookie(c_name)
{
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++)
{
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x === c_name)
{
return unescape(y);
}
}
}
Basically, if I add this to the script, Firebug gives me a Reference Error, FUNCTIONNAME is not defined, with FUNCTIONNAME being whichever other function is called. HOWEVER, if I comment this code snippet out of the script, I don’t receive the error anymore.
Why would this function be doing that? What’s wrong with it?
Ugh, found the problem, and it actually wasn’t related to the code snippet I was providing. Later along, when I was calling the script, it was part of an if statement, like so:
However, this did not appear to work. Setting a value to be equal to fixed the problem, like so:
I’m surprised that this would fix it, but JavaScript has always been my weak point. Thanks anwyays, guys. :/