How can I use code to create a checkbox "does not apply" after a form field question? | XM Community
Skip to main content

I’m trying to add a checkbox with the words “This does not apply to me” after a form field question (just below Reason 5): 

I tried using the following code, but it’s not showing the checkbox. I’ve also confirmed I’m using the correct QID. Any suggestions are appreciated!

 

<script>

Qualtrics.SurveyEngine.addOnload(function() {

    // Get the form field question by its question ID

    var formFieldQuestionId = 'QID37'; // Replace 'QID37' with the actual question ID

    var formFieldQuestion = $(formFieldQuestionId);

 

    // Create a new checkbox element

    var checkbox = document.createElement('input');

    checkbox.type = 'checkbox';

    checkbox.id = 'myCheckbox';

    checkbox.name = 'myCheckbox';

 

    // Create a label for the checkbox

    var label = document.createElement('label');

    label.htmlFor = 'myCheckbox';

    label.appendChild(document.createTextNode('This does not apply to me'));

 

    // Insert the checkbox and label after the form field question

    formFieldQuestion.insertAdjacentElement('afterend', checkbox);

    formFieldQuestion.insertAdjacentElement('afterend', label);

});

</script>

One thing I noticed upon reviewing your script is that you have <script> </script> inserted into the code. This is not necessary when adding JS to Qualtrics. I’m not sure if this is why your code is not functioning correctly but try deleting that part of your code and see if that helps!


Also, add the following code above the question text Rich Content Editor, and update the Q number to the appropriate QID for your question. I tried this on my end and it did the trick: 

<style type="text/css">.Skin inputttype=checkbox] {
position: relative !important;
opacity: 1 !important;
z-index: 999 !important;
height: 20px !important;
width: 20px !important;
}

#QID48\~track {
margin: 50px !important;
}
</style>


That code came from @Tom_1842  in this post: Graphic slider with labels and N/A checkbox | XM Community (qualtrics.com)


Leave a Reply