It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

setCookie is not defined??!

setCookie is not defined??!

Postby windmill on Sun Feb 27, 2011 10:57 pm

Hello ive been getting an error creating a simple cookie and i have no idea why... heres my sample code.

<script type="text/javascript">

function saveIt()
{
var x = prompt("Enter value");

if (!x)
alert('Please fill in a value in the input box.');
else
{
alert('entered');
setCookie('abcdefo',x);
alert('Cookie created');
}
}
</script>

and saveIt() is called via...

<a href="javascript:saveIt()">Create cookie 1</a>

i realise this is terrible code practicing as im not even checking if the cookie already exists but in this case i know it doesnt therefore i dont understand the error. perhaps my syntax is messed somewhere and i just cant see it. also, when i enter a value it does get to the alert('entered'); so it crashes on the setCookie.. i have no idea whats wrong
windmill
 
Posts: 1
Joined: Sun Feb 27, 2011 10:53 pm

Re: setCookie is not defined??!

Postby bardonw on Mon Apr 11, 2011 6:50 pm

I am thinking the issue is the fact that you don't have the setCookie function defined. If you need this function, you can copy the code found here: http://www.w3schools.com/JS/js_cookies.asp.
bardonw
 
Posts: 7
Joined: Tue Feb 15, 2011 4:16 pm


Who is online

Users browsing this forum: No registered users and 6 guests