Track multi choice | Community
Skip to main content
Luca_Lattarini
New Participant
December 12, 2020
Solved

Track multi choice

  • December 12, 2020
  • 1 reply
  • 980 views

 

Hello everyone,

 

How can I track multi-choice and have an evar like this Contemporary Arts|Visual Arts.

Thanks

 

 

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 Brian_Johnson_

@luca_lattarini -

I'd probably create a data element in Launch that's based on custom JS (see below). You'd then just reference the data element in the rule that executes when the form is submitted (or whenever you want to collect the info) to populate your eVar (listVar, listProp...).

var retval = []; var elements = document.querySelectorAll("input[name='interests']"); if (elements.length > 0) { elements.forEach(function (item) { if ((item).checked === true) { var chosenOne = item.parentElement.querySelector("span").innerText; if (chosenOne) { retval.push(chosenOne); } } }); } return retval.join("|");

Assuming the HTML structure matches what's in your post, the above logic checks each checkbox to see if it is checked. If checked, it looks for the related <span> tag to get the name (eg// "Contemporary Arts"). This should work whether there's one option or 100. 

1 reply

Brian_Johnson_
Brian_Johnson_Accepted solution
New Participant
December 14, 2020

@luca_lattarini -

I'd probably create a data element in Launch that's based on custom JS (see below). You'd then just reference the data element in the rule that executes when the form is submitted (or whenever you want to collect the info) to populate your eVar (listVar, listProp...).

var retval = []; var elements = document.querySelectorAll("input[name='interests']"); if (elements.length > 0) { elements.forEach(function (item) { if ((item).checked === true) { var chosenOne = item.parentElement.querySelector("span").innerText; if (chosenOne) { retval.push(chosenOne); } } }); } return retval.join("|");

Assuming the HTML structure matches what's in your post, the above logic checks each checkbox to see if it is checked. If checked, it looks for the related <span> tag to get the name (eg// "Contemporary Arts"). This should work whether there's one option or 100.