Custom validation for multi select question option | XM Community
Skip to main content
Solved

Custom validation for multi select question option

  • November 10, 2023
  • 2 replies
  • 87 views

Forum|alt.badge.img+1

Hi everyone,

I have a survey where I ask participants the following questions: 

 

On the last question (Q14 = QID32), I want the option 'Yes' to be selected only if in the previous question (Q13 = QID31 the 'Name' and 'Company' fields are filled in. I tried to set up a validation rule but was not able to set one for the response option only.

 

Tried the following JS, but it doesn't work. Does anybody know how can I solve this?

 

Qualtrics.SurveyEngine.addOnload(function() {
// Get the values of Name and Company fields from the previous question
var nameValue = "${q://QID31/ChoiceTextEntryValue/1}";
var companyValue = "${q://QID31/ChoiceTextEntryValue/4}";

// Get the Yes option element
var yesOption = jQuery("#QR~QID32~1");

// Get the error message element
var errorMessage = jQuery("<div>Please provide your name and company above.</div>");

// Check if Name and Company fields are not empty
if (nameValue.trim() !== "" && companyValue.trim() !== "") {
// Enable the Yes option
yesOption.prop("disabled", false);

// Remove any existing error message
errorMessage.remove();
} else {
// Disable the Yes option
yesOption.prop("disabled", true);

// Show the error message
jQuery("#QR~QID32").append(errorMessage);
}
});

Thanks in advance!

Best answer by Shashi

We can add following custom validation in Q14:

Q14 Yes is Not Selected

OR (Move to a new logic set)

     Q13 Name is Not empty

     AND Q13 Company is Not empty

 

2 replies

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • Answer
  • November 10, 2023

We can add following custom validation in Q14:

Q14 Yes is Not Selected

OR (Move to a new logic set)

     Q13 Name is Not empty

     AND Q13 Company is Not empty

 


Forum|alt.badge.img+1
  • Author
  • 1 reply
  • November 10, 2023

Oh, this makes total sense and worked perfectly. Thanks a lot Shashi!