I have the following custom form code that displays a thank you message on submit without reloading the page. I'd like to take this a step further and make this conditional. If the field C_Service_Reason is submitted with the value Training, then I don't want the thank you message to display, and instead want them to be redirected to an external URL on success.
Any help with this would be much appreciated, thank you!
<script ></script>
<form id="mktoForm_2338"></form>
<script>MktoForms2.loadForm("//app-sj04.marketo.com", "980-GBD-747", 2338);</script>
<script>
MktoForms2.whenReady(function (form){
//Add an onSuccess handler
form.onSuccess(function(values, followUpUrl){
dataLayer.push({
'event': 'contacttest',
'eventCallback' : function () {
form.getFormElem().hide();
document.getElementById('contacttest').style.visibility = 'visible';
}
});
return false;
});
})
</script>
<div id="contacttest" style="visibility:hidden; text-align: center;">Thank you for your interest! A Hatch expert will be in touch soon.</div>
Solved! Go to Solution.
if ( <condition> ) {
<condition is true action>
} else {
<condition is false action>
}
i.e.
if ( values.C_Service_Reason == "Training" ) {
// do dataLayer stuff
return false;
} else {
// do something else, or do nothing and the regular Thank You URL will load
}
What have you tried? It's a basic JS conditional.
Check the value of values.C_Service_Reason and proceed accordingly.
I very limited JS knowledge, so coming up with the structure of a JS conditional would be beyond me. However, if you could help me with what that would look like for this scenario, I'm familiar enough with JS to adapt the code to other URLs/fields/field values.
Thanks again.
if ( <condition> ) {
<condition is true action>
} else {
<condition is false action>
}
i.e.
if ( values.C_Service_Reason == "Training" ) {
// do dataLayer stuff
return false;
} else {
// do something else, or do nothing and the regular Thank You URL will load
}
Lucho Soto please check the answers on your thread.