0

I have a script which gets the values from the form loaded via JSP to another form from Marketo (as a background form submission).

So far the script is working for values like FirstName and LastName, but when I am trying to pass the values from checkboxes it throws Input Invalid Error Msg from Marketo.

I think, the method I am using is not the right way to pass the values from Salutation Field shown in code.

    mktoForm.addHiddenFields({    

           "Salutation": customForm.querySelector("#mwf8322014b47ad_Frau:checked").value,
           "Salutation": customForm.querySelector("#mwf8322014b47ad_Herr:checked").value,
           "Salutation": customForm.querySelector("#mwf8322014b47ad_Divers:checked").value,

           "FirstName":  customForm.querySelector("#firstname-e9ff1bfe-1321-4a89-9d13-96f9a01648fb").value,
           "LastName":   customForm.querySelector("#lastname-e9ff1bfe-1321-4a89-9d13-96f9a01648fb").value,

.....rest of the fields

I think, the error is because of the second and third Salutation fields which will have null values if I check the Salutation field one.

But I don't know how to pass the values.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
  • 1
    Since you've tagged this jquery (yet not used jquery...) use : `"Salutation":$(customForm).find("#mwf8322014b47ad_Frau").is(":checked"),` – freedomn-m Oct 29 '19 at 08:24

1 Answers1

0

the error is because of the second and third Salutation fields may have null values

Use null coalescence:

"Salutation": 
    customForm.querySelector("#mwf8322014b47ad_Frau:checked").value 
    || customForm.querySelector("#mwf8322014b47ad_Herr:checked").value
    || customForm.querySelector("#mwf8322014b47ad_Divers:checked").value
    || false,

More info: https://stackoverflow.com/a/476445/2181514

freedomn-m
  • 27,664
  • 8
  • 35
  • 57