Skip to main content
February 7, 2018
Solved

How to make my form respond to programatically manipulations of selectmenu?

My form contains the Country selectmenu. When users select United States from that selectmenu, the States selecetmenu appears; when users select a non-US country, the States selectmenu disappears.

The problem is that my form isn't responding to programatically manipulations of the Country selectmenu. When I manually select United States, the State selectmenu appears correctly. But when United States is selected programmatically (for example, by using the following javascript code), the State selectmenu isn't appearing.

document.getElementById('Country').options[1].selected = true;

How do I make my form respond to programatically manipulations of the Country selectmenu?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
February 7, 2018

setValues is a method of an individual Marketo form instance, not a static method of the MktoForms2 object.

So you need to get a handle to the form, e.g.

MktoForms2.getForm(1499).setValues( /* values object */ )

4 replies

SanfordWhiteman
Level 10
February 7, 2018

Never use DOM methods on Marketo forms.  Use the Forms API setValues() method.

Translate
February 7, 2018

Thanks. How do I set values after my form had been initialized? The example in the Examples page seems to combine initialization and value setting together.

I tried the following code but got an error (Uncaught TypeError: MktoForms2.setValues is not a function):

MktoForms2.setValues({ Country: 'United States' });

Translate
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
February 7, 2018

setValues is a method of an individual Marketo form instance, not a static method of the MktoForms2 object.

So you need to get a handle to the form, e.g.

MktoForms2.getForm(1499).setValues( /* values object */ )

Translate