SOLVED

Form : preselect a value within a picklist based on referring URL

Go to solution
Mathias_Saint-1
Level 2

Hi community,

I am wondering if it is possible to preselect a specific value within a form picklist based on the URL which led to the form.

For example, if I have a form asking the contact to choose the type of product he is interested in : "HR", "INDUSTRY", "CPA" etc.

Can I  automatically display the value "INDUSTRY" if the previous visited page is or contains www.mywebsite.com/industry ?

Your inputs are welcome. Thanks for your help.

Mathias.

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

MktoForms2.whenReady(function(form){

     var referrerTypeTable = {

          'INDUSTRY' : [/www\.mywebsite\.com\/industry/],

          'HR' : [/www\.mywebsite\.com\/hr/,/www\.mywebsite\.com\/humanresources/],

     };

     Object.keys(referrerTypeTable).forEach(function(type){

          referrerTypeTable[type].forEach(function(pattern){

               if (pattern.test(document.referrer)) {

                    form.setValues({'ProductType':type});

               }

          });

     });

    

});

View solution in original post

14 REPLIES 14