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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
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);
}
}
Last edited by code?; August 19th, 2008 at 07:24 PM.
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);
};
};
Last edited by javajawa; August 20th, 2008 at 03:20 AM.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
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.
Last edited by javajawa; August 20th, 2008 at 03:24 AM.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
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...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.