Changing hidden field value based on form selection on submit | Community
Skip to main content
December 8, 2017
Solved

Changing hidden field value based on form selection on submit

  • December 8, 2017
  • 3 replies
  • 3813 views

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

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 SanfordWhiteman

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'

      });

    }

});

3 replies

Darrell_Alfons2
Level 10
December 8, 2017

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 4
December 8, 2017

Hi Steven Lim​,

Yes, It is possible through JavaScript.

Thanks!!

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
December 8, 2017

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'

      });

    }

});

December 8, 2017

This looks like it will do the job! Thanks!