Help with cookies using the Colorbox

Hello, I am using the Colorbox code to display a signup form on their first visit utilizing a cookie.
Here is my code:

<script src="http://fredgolfrange.com/colorbox/jquery.min.js"></script>
	<script src="http://www.fredgolfrange.com/colorbox/jquery.colorbox.js"><script>
    <script src="jquery.cookie.js"></script>
	
<script>
        $(document).ready(function () {
            if (document.cookie.indexOf('signupnewsletter=true') == -1) {
                var onehundredeightyDay = 180000 * 60 * 60 * 24 * 1;
                var expires = new Date((new Date()).valueOf() + onehundredeightyDay);
                document.cookie = "signupnewsletter=true;expires=" + expires.toUTCString();
                setTimeout(openColorBox, 1000);
            }
   $.colorbox({iframe:true, width:"85%", height:"85%", href: "http://www.fredgolfrange.com/newsletterhome"});
 }
        });
    </script>

Is there a way to read for the cookie “signupnewsletter” and have the another Colorbox popup if it finds “signupnewsletter” and place a second cookie “important message”?

I see you already got the jquery cookie included, you can use it to check cookie like this

if($.cookie('signupnewsletter'){
// your code here
};

How would I use that code for a Colorbox to pop up showing say our “Contact Us” Page and the popup leave a cookie named “contactinfo”? But after ‘signupnewsletter’ cookie has been place from maybe another visit.


<script>
$(document).ready(function () {
if($.cookie('signupnewsletter'){
  if (document.cookie.indexOf('what=true') == -1) {
                var onehundredeightyDay = 180000 * 60 * 60 * 24 * 1;
                var expires = new Date((new Date()).valueOf() + onehundredeightyDay);
                document.cookie = "what=true;expires=" + expires.toUTCString();
				setTimeout(openColorBox, 1000);
            }
   $.colorbox({iframe:true, width:"85%", height:"85%", href: "http://www.fredgolfrange.com/contactus/"});
}
};	

</script>

I was thinking I could adding this code(above) just below in the code for the Colorbox that places ‘signupnewsletter’ cookie, but it did work.

I meant that it did NOT work. I am still looking for help. Thank for the help so far!

If the cookie is named “signupnewsletter”, it wouldn’t contain the substring “what=true”. The “what” is the name of another cookie.

Also, the construct if ($.cookie(‘signupnewsletter’)) seems dubious to me. $ always returns a jQuery object, so the test will always be true even if the cookie doesn’t exist.

Your main trouble here is that you’re mixing jQuery and JavaScript in inappropriate ways. It’s better to stick to one methodology or the other when working with a cookie or any other object.

Thank you, diggy_dude!

The insight is greatly appreciated!
I still have not been able to figure out how to have another colorbox show if the 1st cookie is already placed.