Results 1 to 3 of 3

Thread: Cookie help

  1. #1
    Join Date
    Oct 2012

    Cookie help

    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?

  2. #2
    Join Date
    Sep 2008
    Jackson MS
    Try == in your if statement and replace the comma with &&.

  3. #3
    Join Date
    Mar 2007
    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.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center