SOLVED

Marketo Form function

Go to solution
Jay00031987
Level 4

Marketo Form function

In a landing page with Marketo Form, below JS is redirecting to else condition only. The given JS is helping to print the rich html content based on Marketo Form value selected from fieldID and rich html text id is myselect.  Can anyone refer the exact if condition rule in Marketo function form in the given JS?

 

<p id="mySelect"> {{lead.First Name}}, dummy text</p>

 

 

 

<script>
MktoForms2.whenReady(function (form) {
    // Put your code that uses the form object here
	var x = document.getElementById("fieldID").value;
  
  if (x == "TRUE") {
    document.getElementById("mySelect").innerHTML = "this is test case-1";
  } else { 	
    document.getElementById("mySelect").innerHTML = "this is test case-2 ";
  }
});
</script>

 

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo Form function

In addition to @msutton's excellent point — you're checking for the literal string "TRUE" as opposed to Boolean keyword true — you're not getting the current value correctly.

 

To check the current value, you do

form.getValues().fieldName

where fieldName is of course the form field name.

 

But even if it's a Boolean field on the Marketo database side, if it's a Checkbox on the form side, the value will indeed be a String.  It will never be the String "TRUE" though. It'll be either "yes" or "no".

 

And please don't use variable names like x.  Variable names must always have semantic meaning.

 

 

View solution in original post

2 REPLIES 2
msutton
Level 2

Re: Marketo Form function

As written your if statement is looking to see if x is equal to the exact string value of "TRUE". 

 

If you just want to see if a value exists, try

if (x==true)

If you want to look for a specific string value, make sure the element you're evaluating actually does contain the exact string "TRUE" as its value.

Does this help?


Mike Sutton
Marketing Operations | DNSFilter.com
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo Form function

In addition to @msutton's excellent point — you're checking for the literal string "TRUE" as opposed to Boolean keyword true — you're not getting the current value correctly.

 

To check the current value, you do

form.getValues().fieldName

where fieldName is of course the form field name.

 

But even if it's a Boolean field on the Marketo database side, if it's a Checkbox on the form side, the value will indeed be a String.  It will never be the String "TRUE" though. It'll be either "yes" or "no".

 

And please don't use variable names like x.  Variable names must always have semantic meaning.

 

 

View solution in original post