Avatar of slegy
slegy
 asked on

Test Value of Retrieved Cookie

I feel foolish posting this question, but I'm completely baffled. I'm simply trying to retrieve a cookie, check its value and do something.
<script type="text/javascript" language="JavaScript">
var loggedIn
function checkLogin()
{
	alert("Get Cookie");
	loggedIn=getCookie("login");
	alert(loggedIn);
	If ((loggedIn == null) || (loggedIn == "NO"))
	{
	alert("Not logged In");
	}
}

function getCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
</script>
<div id="addEvent">
          <input name="addEvent" type="button" value="Add an Event" onclick="checkLogin()" />
        </div>

Open in new window


I've tested with values of null and NO. Both alerts execute, returning values of "null" and "NO" -  and then nothing.
JavaScriptASP

Avatar of undefined
Last Comment
slegy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
slegy

ASKER
Thank you. Sometimes you can't see the forest for the trees. I do feel incredibly foolish!!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy