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
Solved! Go to Solution.
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'
});
}
});
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.
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'
});
}
});
This looks like it will do the job! Thanks!