Is there a way to hide next button until slider value is equal to loop&merge field number? | XM Community
Skip to main content
Solved

Is there a way to hide next button until slider value is equal to loop&merge field number?

  • May 17, 2021
  • 5 replies
  • 25 views

Forum|alt.badge.img+3

Hello,
I would like to use loop and merge function in block with just one slider. The participant has to select number specified in loop and merge field "Select the number ${lm://Field/1} ". In these fields I have random number generator (${rand://int/1:100}). Is there a way, to validate, that participant selected the presented number? If yes, he/she can continue to next loop, if not, he/she can't continue or there is no next button. I was searching for answer, but I can't find solution. Thank you very much.

Best answer by ahmedA

This was quite an interesting question. Add this to your JS:
Qualtrics.SurveyEngine.addOnReady(function () {
    let quest = this,
        ip = quest.questionContainer.querySelector(".ResultsInput"),
        val = "${lm://Field/1}",
        nb = document.querySelector("#NextButton");


    nb.hide();
    ip.onchange = function () {
        if (ip.value == val) nb.show();
        else nb.hide();
    };
});

However, if this is an attention test, I think its a bit too difficult. Demo

5 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • May 17, 2021

This was quite an interesting question. Add this to your JS:
Qualtrics.SurveyEngine.addOnReady(function () {
    let quest = this,
        ip = quest.questionContainer.querySelector(".ResultsInput"),
        val = "${lm://Field/1}",
        nb = document.querySelector("#NextButton");


    nb.hide();
    ip.onchange = function () {
        if (ip.value == val) nb.show();
        else nb.hide();
    };
});

However, if this is an attention test, I think its a bit too difficult. Demo


Forum|alt.badge.img+3

Thank you very much for your reply. I don't know why, but it does not work in my case.
At first I thought it is because other script - I want to have custom button to exit loop&merge. But it does not work even without that script. Do you know why? Also, can use both scripts?
https://stackoverflow.com/questions/25766238/prematurely-exiting-a-loop-and-merge-block-in-qualtrics


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • May 17, 2021

I think what is happening is that the random number is being intialized twice. So there's a difference between the value being fed to the JS and the one to HTML.
Assign

val 
to
parseInt(quest.innerText.replace(/\\D/gm, ""))
and see if it works.


Forum|alt.badge.img+3

https://www.qualtrics.com/community/discussion/comment/37433#Comment_37433I changed It does not work
val = "${lm://Field/1}"
to
val = parseInt(quest.innerText.replace(/\\D/gm, ""))
and it does nothing 😕
I wonder why it works in your demo.
I'm sorry to bother you. I will probably have to do some "me-friendly" manual setup..


Forum|alt.badge.img+3

Thank you very much for your help. I lowered my expectations and used real numbers, it works just fine.