How to use javascript to exclude choices in drilldown based on values in embedded data? | XM Community
Skip to main content
I've got a survey with a drilldown and a matrix table. The drilldown is two levels, department and employee. The contact list has embedded data called "ExcludeEmployee". Upon entering the survey, the first question is the drilldown. I want to use the embedded data "ExcludeEmployee" to exclude that value from the available choices in the drilldown for the employee level. Here is an example:



!



<div class="QuestionOuter BorderColor DD QID1" id="QID1" questionid="QID1" posttag="QID1" data-runtime-remove-class-hidden="runtime.Displayed"> <div id="QR~QID1~VALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.ErrorMsg" data-runtime-html="runtime.ErrorMsg" style="display: none;"></div> <div id="QR~QID1~SDPVALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.PDPErrorMsg" data-runtime-html="runtime.PDPErrorMsg" style="display: none;"></div> <div class="Inner BorderColor DL"> <div class="InnerInner BorderColor"> <fieldset aria-describedby="QR~QID1~VALIDATION QR~QID1~SDPVALIDATION"> <legend> <div class="QuestionText BorderColor">Identify the person you interacted with:</div></legend><div class="QuestionBody"> <table role="presentation" class="ChoiceStructure" cellpadding="0" cellspacing="0"> <tbody> <tr class="reg"> <td> <label for="QR~QID1~1">Department</label> </td> <td> <!-- the html binding blows aways the value binding, so do that last--> <select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~1" id="QR~QID1~1" data-runtime-select-options="runtime.Choices.1.optionHTML" data-runtime-enabled="runtime.Choices.1.enabled" data-runtime-value="runtime.Choices.1.Value"><option aria-label="Blank"></option>

<option value="1">Human Resources</option>

<option value="5">Accounting</option>

<option value="9">Sales</option></select> </td> </tr> <tr class="alt"> <td> <label for="QR~QID1~2">Employee</label> </td> <td> <!-- the html binding blows aways the value binding, so do that last--> <select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~2" id="QR~QID1~2" data-runtime-select-options="runtime.Choices.2.optionHTML" data-runtime-enabled="runtime.Choices.2.enabled" data-runtime-value="runtime.Choices.2.Value"><option aria-label="Blank"></option>

<option value="2">Mickey Mouse</option>

<option value="3">Pluto</option>

<option value="4">Donald Duck</option></select> </td> </tr> </tbody> </table></div> </fieldset> </div> </div> </div>



The embedded data "ExcludeEmployee" may contain "Mickey Mouse", in which case I'd want to hide that employee from the second choice group in the drilldown (dropdowns). I need to expose this embedded data somehow to the javascript for use, I'm not familiar enough to suggest/know how that might be done.



It's probably important to note that the above image displays what I see after I choose a department from the drilldown. By default, upon entering the survey, there are only choices in the department level of the drilldown and the employee level is empty (because I haven't drilled down into a department yet). Here is the code for the drilldown in it's default state after entering the survey:



<div class="QuestionOuter BorderColor DD QID1" id="QID1" questionid="QID1" posttag="QID1" data-runtime-remove-class-hidden="runtime.Displayed"> <div id="QR~QID1~VALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.ErrorMsg" data-runtime-html="runtime.ErrorMsg" style="display: none;"></div> <div id="QR~QID1~SDPVALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.PDPErrorMsg" data-runtime-html="runtime.PDPErrorMsg" style="display: none;"></div> <div class="Inner BorderColor DL"> <div class="InnerInner BorderColor"> <fieldset aria-describedby="QR~QID1~VALIDATION QR~QID1~SDPVALIDATION"> <legend> <div class="QuestionText BorderColor">Identify the person you interacted with:</div></legend><div class="QuestionBody"> <table role="presentation" class="ChoiceStructure" cellpadding="0" cellspacing="0"> <tbody> <tr class="reg"> <td> <label for="QR~QID1~1">Department</label> </td> <td> <!-- the html binding blows aways the value binding, so do that last--> <select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~1" id="QR~QID1~1" data-runtime-select-options="runtime.Choices.1.optionHTML" data-runtime-enabled="runtime.Choices.1.enabled" data-runtime-value="runtime.Choices.1.Value"><option aria-label="Blank"></option>

<option value="1">Human Resources</option>

<option value="5">Accounting</option>

<option value="9">Sales</option></select> </td> </tr> <tr class="alt"> <td> <label for="QR~QID1~2">Employee</label> </td> <td> <!-- the html binding blows aways the value binding, so do that last--> <select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~2" id="QR~QID1~2" data-runtime-select-options="runtime.Choices.2.optionHTML" data-runtime-enabled="runtime.Choices.2.enabled" data-runtime-value="runtime.Choices.2.Value" disabled=""></select> </td> </tr> </tbody> </table></div> </fieldset> </div> </div> </div>



So I need to have javascript that runs any time the second choice group is populated to exclude the choice from those that are being populated? Does anyone have a solution or suggestions on how I might accomplish this?



Also, separately from the above, I will need to do this same thing to multiple choices in the employee level of the drilldown based on a comma delimited list of exclusions in embedded data. For instance, "Mickey Mouse,Pluto" in an embedded data field called "ExcludeEmployeeMultiple". I suppose it doesn't matter whether or not it's separate, it just matters that the javascript function that is doing the filtering/exclusion can handle multiple input values, of type comma delimited list (in which case the first example would be a list with only one value). Or I need to be able to run the function once for each of the embedded data fields mentioned.



Thank you in advance for your consideration and help.

JavaScript can be one of the solution, but you can also apply custom validation


I've investigated custom validation and I'm not sure how it would apply in this case, please elaborate.

I would be very interested in seeing a solution to this as well


Been looking for something similar to this, and am interested to see a solution.


cess , it seems like the "ExcludeEmpdloyee" embedded data containing "Mickey Mouse" over simplify setting. For example, do you want to only exclude "Mickey Mouse" when the user select "Human Resource"? or you want to exclude "Mickey Mouse" regardless of which "Department" a user choose.


Good question, thanks. In this scenario, to simplify things and avoid a more complicated solution, I'm assuming the employee name is unique. So, exclude "Mickey Mouse" regardless of the department chosen. But a solution that takes both variables into account "Mickey Mouse" and "Human Resources" would be fine as well.


Leave a Reply