hub.eb?material_id=387&track_id=386

Introduction to JavaScript API Client


The client interface provides information and functions pertaining to the client browser including:

  • current request and response objects
  • creating and reading cookies
  • capabilities of the client browser e.g. if cookies are enabled

Steps


1

Create a form and add a field to the page called emailAddress and add a button called myEmailAddressCookieButton.

2

Attach an On Click script to the button called myEmailAddressCookieButton and paste the following code:

// set the email cookie to the value of the email address field
if(fields.emailAddress.value){
   // add a cookie that expires in 60 seconds
   client.addCookie("email_address_cookie", fields.emailAddress.value, 60);
}
else{
   event.owner.addErrorMessage("Please enter an email address")
}

 

3

Attach a Before Page script and paste the following code:

// if the email cookie has a value set it to the field
if(client.getCookieValue("email_address_cookie")){
   fields.emailAddress.value = client.getCookieValue("email_address_cookie");
}
4

Run the form and enter an email address and click the button to create the email address cookie.

Rerun the form and notice how the email address field has been prepopulated.

Current Module

Related