Set Cookie

Definition:

NDLLibrary.setCookie(cookieName, value, expiry)

 

Description:

Save a string to a cookie on the user's local machine.

 

Parameters:

This function has three parameters:

cookieName - Required

A name of your choice for the cookie to be created. The name is case-sensitive.

 

value - Required

The string of characters you want to be stored in the cookie.

 

expiry - Required

The length of time you want the cookie to be retained, in days. If you specify 0 (zero), the cookie will expire straight away

Note: This function does not use the default ndlParams object.

 

Returns:

true

 

Code Sample:

// Store user's name in a cookie

var cookieName= "myCookie",

value = username + " " + usersurname,

expiry = 5;

return NDLLibrary.setCookie(cookieName, value, expiry);

 

Notes:

If you are using cookies in your form, you will need to display an appropriate warning message within the form and allow users to refuse the use of cookies.

 

Using as Predefined Action in Event:

When assigned to an Event as a predefined action, you will need to generate a JavaScript function and then edit the skeleton script created to provide a name for the cookie, the value to store in it and how long you want the cookie to be retained. The automatically generated code looks like this:

return NDLLibrary.setCookie(ndlParams);

You will see in the code sample above we have added the lines:

var cookiename= "myCookie",

value = username + usersurname,

expiry = 5;

before the line calling the function. You will need to add similar lines with the following changes:

- Substitute myCookie with the name you want to give your cookie, leaving the double quotes around it.

- Substitute username + " " + usersurname with the value you want to store. If you are specifying a text string, e.g. John Smith, you will need to enclose the text in double quotes, e.g. "John Smith".

- substitute the 5 in the line var expiry = 5 with a number representing the number of days you want the cookie to be retained.

 

 


See also:

Get Cookie

Remove Cookie

Save Form

Restore Form