I want to set a cookie when an <a> is clicked. The cookie for the numerous a's will be set as checked. If all the cookies has been set to checked, an alert box will open. I've started for example with this simple html and javascript:
function setSessionCookie1() {
document.cookie="cookie1" + checked;
}
function setSessionCookie2() {
document.cookie="cookie2" + checked;
}
function CheckIfCookiesAreChecked() {
if (cookie1=checked, cookie2=checked) {
alert ("Both the <a>'s have been clicked");
}
<a href="page1.html" onclick="setSessionCookie1">Click here for page 1</a>
<a href="page2.html" onclick="setSessionCookie2">Click here for page 2</a>
I know the code doesn't work above, but my question is how to get it to work.
How do I set an <a> on checked after onclick, and how do I properly check if the <a>'s have been checked so JavaScript knows when to show the alert?
11-13-2012, 08:46 AM
wbport
Try == in your if statement and replace the comma with &&.
11-13-2012, 11:53 AM
Logic Ali
Unless you mean every link on the page, you need to identify which links are involved.
Use ONE cookie only, whose value is comprised of a comma-delimited list if all clicked IDs. As each link is clicked, if its ID is not in the cookie already, add it preceded by a comma.
When the list contains all the IDs in the group, show your alert.