Syntax Error In While Statement
Okay, I keep getting a syntax error in my firebug add-on, and it cannot figure out what is causing the problem, but it gives me
Quote:
function udf_ToggleUserStyle(box, id){if...ile (var i < newCookie.length && found =
The whole while statement is
Code:
var i = 0
while (i < newCookie.length && found == false)
{
if (id == newCookie[i]) { found = true; }
i++;
}
If you need the whole function, I can get it too, It's not long.
Re: Syntax Error In While Statement
That isn't enough to go by. Where was newCookie defined? Why are you using a while statement instead of for? Also, instead of found == false, why don't you use !found?
Re: Syntax Error In While Statement
Quote:
Originally Posted by PeejAvery
That isn't enough to go by. Where was newCookie defined? Why are you using a while statement instead of for? Also, instead of found == false, why don't you use !found?
lol is that better, cleaner, or faster? never knew that.
This is a script that I ported (which i rarely do), but unfortunately this is what happens, I can usually solve it on my own.
Code:
{
if (box.checked)
{
var oldCookie = String(getCookie('scriptBlockList'));
if (oldCookie == 'null') { oldCookie = ''; }
var newCookie = oldCookie.split(',');
var found = false;
i = 0;
while (var i < newCookie.length && found == false)
{
if (id == newCookie[i]) { found = true; }
i++;
}
if (!found)
{
newCookie.push(id);
var exdate = new Date();
exdate.setDate(exdate.getDate() + 100);
setCookieWithExpires('scriptBlockList', newCookie, exdate);
}
}
else
{
var oldCookie = String(getCookie('scriptBlockList'));
if (oldCookie == 'null') { oldCookie = ''; }
var newCookie = oldCookie.split(',');
found = false;
i = 0;
while (i < newCookie.length && found == false)
{
if (id == newCookie[i]) { found = true; }
i++;
}
arrStart = newCookie.slice(0,i-1);
arrFin = newCookie.slice(i,newCookie.length);
newCookie = arrStart.concat(arrFin);
var exdate = new Date();
exdate.setDate(exdate.getDate() + 100);
setCookieWithExpires('scriptBlockList', newCookie, exdate);
}
}
Re: Syntax Error In While Statement
First, here's a considerably neater version of that code. I'll see what debugging I can do soon, although knowing what id is (I'm guessing some number), what the cookie normally looks like (guessing the result of the !box.checked segment). I'm happy with box.checked...
Code:
function ??? {
var found = false; var i = 0;
var oldCookie = String(getCookie('scriptBlockList'));
if (oldCookie == 'null') {
oldCookie = '';
};
var newCookie = oldCookie.split(',');
for (i = 0; i < newCookie.length; i++) {
alert(newCookie[i])
if (id == newCookie[i]) {
found = true;
i = newCookie.length;
};
};
var exdate = new Date();
exdate.setDate(exdate.getDate() + 100);
if (box.checked) {
if (!found) {
newCookie.push(id);
setCookieWithExpires('scriptBlockList', newCookie, exdate);
};
} else {
arrStart = newCookie.slice(0,i-1);
arrFin = newCookie.slice(i,newCookie.length);
newCookie = arrStart.concat(arrFin);
setCookieWithExpires('scriptBlockList', newCookie, exdate);
};
};
Re: Syntax Error In While Statement
I think the id is a user name
1 Attachment(s)
Re: Syntax Error In While Statement
Ok. there are no syntax errors I can find in the code of my last post. However, I don't have any of your cookie functions or data.
The attached file is the testing bed I used.
Re: Syntax Error In While Statement
Okay, your code works perfectly, i forgot to add that box and id were function arguments.
Anyways, now I face a slightly small problem. I made it really simple and divided it up so i could see what the problem is, and it seems to be the single quote.
(took out some attributes for simplicity)
Code:
var userID = "bob99";
var temp2 = "'" + userID + "'"; //alerts 'bob99' with alert()
var temp = "onchange='toggleUserStyle(this, " + temp2 + ");'";
It ends up giving me trouble, and looking like this...
Code:
<input );="" a10m1c="" onchange="toggleUserStyle(this, "/>
I want it like this... example username
Code:
<input onchange="togglerUserStyle(this, 'bob99');" />