Tokenizing Picklists? | Community
Skip to main content
September 12, 2015
Solved

Tokenizing Picklists?

  • September 12, 2015
  • 2 replies
  • 3665 views

Greetings, Marketo Community,

As our office continues to build out our landing pages and forms, we are struggling to keep our product (in this case, degree programs at a university) picklist up to date. Currently, we have over 30 picklist options for programs within our forms.

Is there a way to create a token - universal or at the folder level - that will allow for easy picklist updating when new programs are added, program names are changed, etc?

Thanks in advance,

Matt

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

 Apologies, I'm still new to writing script.
If I wanted to make my form picklist values dynamic via javascript what would that look like?

We built one that does it for all  the field labels and submit button, however it's not picking up the div id tags on our rich text fields, and I also haven't been able to create any logic with the picklist field values.


Another idea I had was leaving the picklist field values off the form and instead try to build logic into the below script but I don't know where to add it. 

If text token {{my.program_language}} = french then vallues populate with french values and english stored, then continue for other languages. 
The program language is set in a text token. 

<script> MktoForms2.whenReady(function(form) { var formEl = form.getFormElem()[0], selectEl = formEl.querySelector("#Territory__c"); (IF {{my.program_language}} = English) var optionList = [ { label: "English1", value: "ENG1" }, { label: "English2", value: "ENG2" }, { label: "English3", value: "ENG3" } ]; optionList.forEach(function(optionDesc) { var newOption = new Option(); newOption.text = optionDesc.label; newOption.value = optionDesc.value; selectEl.add(newOption); }); (IF {{my.program_language}} = French var optionList = [ { label: "French1", value: "ENG1" }, { label: "French2", value: "ENG2" }, { label: "French3", value: "ENG3" } ]; optionList.forEach(function(optionDesc) { var newOption = new Option(); newOption.text = optionDesc.label; newOption.value = optionDesc.value; selectEl.add(newOption); }); });</script>

 


JS if looks like this:

if( condition ) { // do something }

 

Therefore you could use your {{my.token}}, provided the value is allowed within a JS double-quoted string:

if( "{{my.program_language}}" == "English" ) { // do something }

 

However I’d be very unlikely to do it this way. It’s always better to keep JS code out of your LPs and templates.

 

Instead, store the code in a separate .js file you put in Design Studio. Include a different src based on the {{my.token}}, as shown in my earlier post.

2 replies

SanfordWhiteman
New Participant
September 14, 2015

Matthew, are your forms on Marketo-hosted Landing Pages?

September 14, 2015

Sanford - we use the form fields through Marketo, but place the forms on our institutional pages via iframes.

SanfordWhiteman
New Participant
September 14, 2015

OK, IFRAME is still Marketo-hosted for our purposes.

There are a few different ways to create shareable picklists.  If you want to use a (text) token here's what you can do:

1. Create the token.  It will actually be snippet of simple JavaScript that has all your options in it. Here, I have just copy-and-pasted the code from http://codepen.io/figureone/pen/ZbQbpK.js.  You can use that script as your boilerplate, as it should be easy to see where to plug in the dropdown text and values.  Marketo helpfully removes the carriage returns so it all works on one line.

2. Add the {{my.picklist}} token to your LP in an HTML element (after adding the Form element).

3. Profit!

Here it is in action on a Landing Page: Dynamic Picklist​.  You can see that I've added 3 new options to the ones stored in the form descriptor itself. This picklist could also have started from scratch, of course.

September 14, 2015

Matthew Hendrickson​ Great question. FYI. I moved your post to the Products and Support​ where one of our experts is more likely to find it.

September 14, 2015

Scott - thanks! I'm still fumbling around trying to find the right place for things around here.

-Matt