How to display logic text entry box in matrix question | XM Community
Solved

How to display logic text entry box in matrix question

  • 30 November 2023
  • 6 replies
  • 67 views

Badge +1

I have a matrix question, with 8 statements and 8 scale points. The 8th scale point is hiden for statements 1-7. The 8th statement has a text entry because is “Other (specify)”.

 

What I need is to hide the text entry when the 8th scale point is selected for the 8th statement, and show it when any of the other scale points are selected in this statement.

 

I attach a screenshot of my question and a basic code that I tried to format on my specifications but failed. 

 

Can anyone help me with this?

 

Javascript code:

Qualtrics.SurveyEngine.addOnReady(function() {
    var qid = this.questionId;
    var text = document.getElementById("QR~" + qid + "~3~TEXT");

    jQuery(text).css("display", "none");

    // Assuming the scale points are represented by radio buttons in the third row
    jQuery("#" + qid + " tbody tr:eq(2) input[type=radio]").eq(0).change(function() {
        if (jQuery(this).prop("checked")) {
            jQuery(text).css("display", "block");
        } else {
            jQuery(text).css("display", "none");
        }
    });
});
 

 

 

icon

Best answer by Deepak 30 November 2023, 20:20

View original

6 replies

Userlevel 7
Badge +36

@mc1999 

Try below code:

Kindly change the Id as required.

Qualtrics.SurveyEngine.addOnReady(function() {
var qid = this.questionId;

jQuery('#' + qid).change(function() {
var isChecked = jQuery('[id="QR~' + qid + '~8~8"]').prop("checked");
jQuery('[id="QR~' + qid + '~8~TEXT"]').toggle(!isChecked);
});
});

Hope it helps!

Badge +1

Hi Deepak!

I tried the code you write, but it doesn’t work as expected.

Can you suggest any other piece of code that can help me?

Thank you!

Userlevel 7
Badge +36

@mc1999 

If the below GIF is what is required the code works you need to change the ID I believe in code

 

Badge +1

Yes, that is the behaviour I need. In which of the following statements do I need to make changes?

  1. '[id="QR~' + qid + '~8~8"]'
  2. '[id="QR~' + qid + '~8~TEXT"]'

And, where I can find the correct id?

Userlevel 7
Badge +36

@mc1999

You can inspect the radio button as well as text box and get the ID’s.

Preview the question right click and inspect the radio button and text box you will get the required id’s. First is radio button second is text box.

In the code you provided in question you have id’s included there as well so you can check if it’s the same.

or just delete that question and create new the code should directly work.

Badge +1

Great, Deepak!

Now it’s working perfectly, thank you!

Leave a Reply