How can I change multiple field values with only one select? | Community
Skip to main content
Nick_Deboo1
Level 2
May 27, 2016
Solved

How can I change multiple field values with only one select?

  • May 27, 2016
  • 1 reply
  • 2465 views
Form
  • First name
  • Last name
  • Email
  • Country
  • I'm a (which is a field called "Lead type")
    • Student | Student
    • Teacher | Lead
    • Other | Lead

How can I change the "Industry" when the visitor chooses "Teacher"? This should write "Education" in there?

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 Nick_Deboo1

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form){

    var el = document.getElementById("teklaLeadType");

    var sel = el.options[el.selectedIndex].innerHTML;

    switch (sel) {

      case 'Teacher':

        form.addHiddenFields({Industry:'Education'});

        break;

      case 'Some other type':

        form.addHiddenFields({Industry:'Some other industry'});

        break;

      default:

    }

  });

})

1 reply

SanfordWhiteman
Level 10
May 27, 2016

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form){

    switch (form.getValues()['Lead_Type']) {

      case 'Teacher':

        form.addHiddenFields({Industry:'Education'});

        break;

      case 'Some other type':

        form.addHiddenFields({Industry:'Some other industry});

        break;

      default:

    }

  });

});

Obviously you need to use the exact names of your fields, which you can see by inspecting the form's HTML or looking in Field Management.

Nick_Deboo1
Level 2
May 27, 2016

I cried victory too quick.

It seems that the form.getValues()['Lead_Type'] takes the values and not the labels. If the label is teacher, the getvalues take "Lead" as value.

Nick_Deboo1
Nick_Deboo1AuthorAccepted solution
Level 2
May 27, 2016

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form){

    var el = document.getElementById("teklaLeadType");

    var sel = el.options[el.selectedIndex].innerHTML;

    switch (sel) {

      case 'Teacher':

        form.addHiddenFields({Industry:'Education'});

        break;

      case 'Some other type':

        form.addHiddenFields({Industry:'Some other industry'});

        break;

      default:

    }

  });

})