I want to retrieve some data from a form via JavaScript, and have them in JavaScript variables

  const value = document.getElementById("my-field").value;

After that I want to pass this client side JavaScript into AMPscript expression, so I can send data using ajax and will be sent encrypted ( client side )

  // my variables has to replace the values of email, firstname, lastname, etc .. 

  var expression = '%%=CloudPagesURL(2102, "email", "edm@edm.com" , "firstname", "firstName", "lastname", "el second name")=%%'

  xhttp.open("POST", expression, true);

  //Send the proper header information along with the request

  xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');


Is there a way to do that?

1 Answer 1


Yes you can, try these functions:

Overview: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_utilitiesVariable.htm

AMPscript -> SSJS: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_utilitiesVariableGetValue.htm

SSJS -> AMPscript: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_utilitiesVariableSetValue.htm

  • But this is a server side Javascript, while mine is client side JS
    – TaouBen
    Sep 24, 2021 at 9:21
  • AMPscript is serverside; you can only interact with it on the server side. Sep 24, 2021 at 9:24
  • so in my case, there is no way to insert my client side js variables into the ampscript expression
    – TaouBen
    Sep 24, 2021 at 9:29
  • The only way you could achieve this is by making a custom cloud page API end point and call it using Ajax/JS. This would be insecure though and not recommend Sep 24, 2021 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .