Newbie here. If we have a slider question and we wish to adjust let's say the minimum, maximum and starting values based on the response to a previous question using javascript, how can we do so? To clarify, let's say someone answers 40 for Question1. For Question2, we now wish to dynamically limit the slider value maximum value to 40 (response to Question1), minimum value to 40/10 (one-tenth of response to Question1) and starting point to 40/2 (half of response to Question1). Please could someone kindly share the corresponding javascript that I could add to Q2 to make it work. Thanks.
Hi
Here’s the script you can drop into Question 2 (the slider question). This assumes that Question 1 stores a numeric value using Embedded Data or as part of a previous question’s response.
Qualtrics.SurveyEngine.addOnload(function() {
// Get the response from Question 1
var q1Value = parseFloat("${q://QID1/ChoiceNumericEntryValue}"); // Replace QID1 with actual QID of Question 1
if (!isNaN(q1Value)) {
var min = q1Value / 10;
var max = q1Value;
var start = q1Value / 2;
// Access the slider input
var slider = document.querySelector('inputqtype="range"]');
if (slider) {
slider.min = min;
slider.max = max;
slider.value = start;
// Optional: update the display value manually
var display = document.querySelector('.track > .handle > .value');
if (display) {
display.innerText = Math.round(start);
}
}
}
});
- Make sure Question 1 is on a separate page from Question 2 so the value is available at runtime.
- You can get the QID of Question 1 from the browser URL or Qualtrics “Advanced Question Options.”
- This script works for standard Qualtrics sliders — if you’re using custom styling, the selector might need to be adjusted
Let me know if it helps!
-- Rochak
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.