Hi everyone,
I'm experiencing an issue with custom sliders in Qualtrics using JavaScript. Visually, everything works as expected—the sliders appear and can be moved. However, the responses are not being recorded.
- When the question is required, moving the slider does not register as an answer. I still get the validation message saying that I need to answer the question before proceeding.
- When the question is not required, I can proceed to the next page, but the response is not stored.
It seems like Qualtrics does not recognize the slider interaction as an actual response. Has anyone encountered this issue before, or does anyone know how I can fix this so that the answers are properly saved?
Any help would be greatly appreciated!
Thanks in advance.
This is the JS-code i’ve used:
Qualtrics.SurveyEngine.addOnload(function() {
// Get the question container
var container = this.getQuestionContainer();
// Hide the original Qualtrics question text and body
container.querySelector('.QuestionText').style.display = 'none';
container.querySelector('.QuestionBody').style.display = 'none';
// Create our custom sliders
var customSliders = document.createElement('div');
customSliders.innerHTML = `
<div style="margin-bottom: 20px;">Question</div>
<div class="custom-sliders" style="max-width: 100%; padding: 0 10px;">
<div class="slider-container" style="margin: 20px 0; max-width: 100%;">
<div class="slider-labels" style="display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 14px;">
<span style="color: #333;">option 1</span>
<span style="color: #333;">option 2</span>
</div>
<input type="range" id="slider1" name="slider1" min="0" max="100" value="50" style="width: 100%; max-width: 100%;">
</div>
</div>
`;
// Add responsive styles to the container
container.style.maxWidth = '100%';
container.style.overflowX = 'hidden';
container.style.padding = '0 10px';
// Insert our custom sliders
container.insertBefore(customSliders, container.firstChild);
// Function to update Qualtrics data
const updateQualtrics = (index, value) => {
const inputs = container.querySelectorAll('input[type="text"]');
if (inputs[index]) {
inputs[index].value = value;
var event = document.createEvent('HTMLEvents');
event.initEvent('change', true, true);
inputs[index].dispatchEvent(event);
}
};
// Add event listeners to update Qualtrics data
['slider1', 'slider2', 'slider3'].forEach((sliderId, index) => {
document.getElementById(sliderId).addEventListener('input', function() {
updateQualtrics(index, this.value);
});
});
});