SOLVED

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

Go to solution
Highlighted
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level 10 - Community Moderator

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

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 */ )

View solution in original post

4 REPLIES 4
Highlighted
Level 10 - Community Moderator

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

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

Highlighted
Anonymous
Not applicable

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

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' });

Highlighted
Level 10 - Community Moderator

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

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 */ )

View solution in original post

Highlighted
Anonymous
Not applicable

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

Thank you very much. I see.