SOLVED

Changing hidden field value based on form selection on submit

Go to solution
Anonymous
Not applicable

Changing hidden field value based on form selection on submit

Hello Marketo community,

I'm working on a form with radio buttons, and based on these radio buttons I was looking to change a hidden form field's value when a registrant submits the form. Is it possible to dynamically change this value in real-time?

My alternative solution was to have a trigger listen in on the form fill selection and changing the field value after form submission. I wanted to know if this could be done in real-time on the form itself?

Thanks

Steven

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Changing hidden field value based on form selection on submit

The Forms API addHiddenFields method is designed for this case, ergo:

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form){

    var currentValues = form.getValues();

    if ( currentValues['myVisibleField'] == 'my interesting value' ) {

      form.addHiddenFields({

       'myHiddenField' : 'my hidden dependent value'

      });

    }

});

View solution in original post

4 REPLIES 4
Darrell_Alfons2
Level 10 - Champion Alumni

Re: Changing hidden field value based on form selection on submit

Hey Steven, I don't think you can change it in real time.

I would do the alternative method you are proposing, which is to change the value with a trigger campaign.

Akshay_Pant
Level 5

Re: Changing hidden field value based on form selection on submit

Hi Steven Lim​,

Yes, It is possible through JavaScript.

Thanks!!

SanfordWhiteman
Level 10 - Community Moderator

Re: Changing hidden field value based on form selection on submit

The Forms API addHiddenFields method is designed for this case, ergo:

MktoForms2.whenReady(function(form){

  form.onSubmit(function(form){

    var currentValues = form.getValues();

    if ( currentValues['myVisibleField'] == 'my interesting value' ) {

      form.addHiddenFields({

       'myHiddenField' : 'my hidden dependent value'

      });

    }

});

Anonymous
Not applicable

Re: Changing hidden field value based on form selection on submit

This looks like it will do the job! Thanks!