Hi all,

Here's the code I've come up with. I deliberately left off an expiration date since I want the cookie to expire when the browser is closed.

<html>
<head>
<script type="text/javascript">

function setCookie(name,value)
{
document.cookie=name+"="+value;
}

</script>
</head>
<body>
<a href="#" onClick="createCookie('Role',Parent)";>Parent</a>
<a href="#" onClick="createCookie('Role',Student)";>Student</a>
</body>
</html>

I've tried many many things but can't figure it out. I don't understand what I'm doing wrong.

Any help would be appreciated.

Thanks

Your function is called "setCookie" but you are calling "createCookie" in your onclick event. Change either the function name or the call so they match.

Well I got it working. Here's my new code:

<html>
<head>
<script type="text/javascript">

function setCookie(value)
{
document.cookie="Role="+value;
}

</script>
</head>
<body>
<a href="#" onClick="setCookie('Parent')";>Parent</a>
<a href="#" onClick="setCookie('Student')";>Student</a>
</body>
</html>

Thanks Practicality.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.