SOLVED

Changing hidden field value based on form selection on submit

Go to solution
Anonymous
Not applicable

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
SanfordWhiteman
Level 10 - Community Moderator

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
SanfordWhiteman
Level 10 - Community Moderator

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

This looks like it will do the job! Thanks!

Akshay_Pant
Level 5

Hi Steven Lim​,

Yes, It is possible through JavaScript.

Thanks!!

Darrell_Alfons2
Level 10 - Champion Alumni

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.