Created
April 26, 2017 00:44
-
-
Save javanigus/71898d7e696c4e76dfc118bd31053fc4 to your computer and use it in GitHub Desktop.
Change Some Marketo Hidden Field Values Depending on Another Field's Value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://developers.marketo.com/javascript-api/forms/ | |
/* Using Forms 2.0 from Landing Pages | |
While all of the forms examples use embedded forms, the same APIs are available on Marketo Landing Pages as well. | |
Usually, you’ll want to add a script that gets some reference to the form object. To do this, first add your form to the landing page, then add a new HTML block to your landing page. Then you can add a script block to the page as follows */ | |
MktoForms2.whenReady(function (form) { | |
var selectedPackage, Marketing_Asset_Id_Current__c, last_mkt_asset, Company_Size_Range__c_account, formTrialPackageType; | |
// http://developers.marketo.com/rest-api/assets/forms/examples/ | |
// Add onSubmit handler | |
form.onSubmit(function(){ | |
// when user clicks a "package" radio button, get the selected package | |
selectedPackage = $("[name='formTrialPackageType']").val(); | |
// depending on the package value, set asset ID and company size values | |
switch(selectedPackage) { | |
case "Express Lite": | |
Marketing_Asset_Id_Current__c = "307"; | |
last_mkt_asset = "307"; | |
Company_Size_Range__c_account = "1-250"; | |
break; | |
case "Express": | |
Marketing_Asset_Id_Current__c = "306"; | |
last_mkt_asset = "306"; | |
Company_Size_Range__c_account = "251-5000"; | |
break; | |
case "Enterprise": | |
Marketing_Asset_Id_Current__c = "305"; | |
last_mkt_asset = "305"; | |
Company_Size_Range__c_account = "5000+"; | |
break; | |
case "Consultant": | |
Marketing_Asset_Id_Current__c = "308"; | |
last_mkt_asset = "308"; | |
Company_Size_Range__c_account = "Security Consultant"; | |
break; | |
} | |
// update hidden field values | |
$("[name='Marketing_Asset_Id_Current__c']").val(Marketing_Asset_Id_Current__c); | |
$("[name='last_mkt_asset']").val(last_mkt_asset); | |
$("[name='Company_Size_Range__c_account']").val(Company_Size_Range__c_account); | |
// use this block during testing to display values in the console | |
// remove this block in production | |
// Check if the form is submittable | |
if (form.submittable()) { | |
// Set it to be non submittable | |
form.submittable(false); | |
console.log("Marketing_Asset_Id_Current__c = " + $("[name='Marketing_Asset_Id_Current__c']").val()); | |
console.log("last_mkt_asset = " + $("[name='last_mkt_asset']").val()); | |
console.log("Company_Size_Range__c_account = " + $("[name='Company_Size_Range__c_account']").val()); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment