I have a HTML Form with AJAX code

   <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>

    function fChnage(){
    var zipname = $('#zValue').val();
    var emailname = $('#eValue').val();
    type: "POST",
    url: "https://pub.s7.exacttarget.com/123",
    data: { Zip: zipname,Email:emailname },
    dataType: "html",
    async: false,

 <h2>Home insurance Form</h2><div>
 <form action="https://pub.s7.exacttarget.com/123" id="myForm"method="post">
Zip Code:<br>
<input name="Zip" placeholder="Zip Code" type="text" id="zValue" onchange="fChnage()"> 
  <input name="Email" placeholder="Email address" type="text" id="eValue" onchange="fChnage()">
  <input type="button" value="Buy" id="btnTest">&nbsp;</form></div> 

Processing Page

    var @Zip,@Email 
    set @Zip = RequestParameter('Zip') 
    set @Email = RequestParameter('Email') 

     If Not Empty(@Email) Then

My current code is not working means its not posting any records to DE. Can i get any help on this?


I don't have an immediate answer for your script issue, but I have some words of advice and guidance which might save you in the long-term.

You intended script will post to a SFMC cloud page upon every change url: "https://pub.s7.exacttarget.com/123",

This will become very costly (unless you have an agreement with Salesforce we're unaware of); as Salesforce charge by Super Message for each Cloudpage view / visit (not unique visit, but actual hits).

So if your AJAX processing script manages to keep updating the data extension values upon each field change, then you will get a lot of action happening.

A method I did accomplish for a client, who needed a 'Language Changer' on their form i.e. a contact is redirected to a Preference Centre which is in English, they can select a language from a dropdown and it would save the language selection on their profile and refresh the page in their chosen language.

I accomplished this using a function :

function LanguageChanger() {
document.getElementById("overlay").style.display = "block";     
document.getElementById("submitted").value = "lang_change";    

LanguageChanger() was called as an OnChange action in the form:

     <select style="text-align: :right;
     float: right;" name="Language" id="Language" onchange="LanguageChanger()">
   <option value="en-GB" %%[IF @language=='en-GB' Then ]%% selected %%[endif]%% >English</option>
   <option value="fr-FR"  %%[IF @language=='fr-FR' Then ]%% selected %%[endif]%%>French</option>       

My processing page was the same as the form page, and upon Submit / Load there was a conditional statement to see if Language was changed :

Set @submitted = RequestParameter("submitted")
Set @Language = IIF(EMPTY(RequestParameter("lang")),'en-GB',RequestParameter("lang"))

/* LANGUAGE CHANGER SUBMIT - this has to be handled separately from a normal submit*/

  IF (@submitted == "lang_change")Then
          var @EmailAddress
          /*If yes then get all post values */
          Set @SubscriberKey = RequestParameter("email")
          Set @EmailAddress = RequestParameter("email")
          Set @Language = RequestParameter("language")

          /* Perform upsert */
          UpsertData('DataExtensionName',1,'EmailAddress', @EmailAddress, 
          'Language', @Language


Hope this helps as an explanation of how I got around the requirement. Again, this solution limits how many page calls are being made - it only loads for when a single field (Language) is changed.

  • i agree with you that Onchange() method will make multiple calls to cloud page but i have more then 10 fields in my form so i want to capture only the email address and may be First name to re-target them with email and i want to capture email address immediately when they enter it. Oct 5 '18 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.