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

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


Badge +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.

icon

Best answer by ahmedA 17 May 2021, 15:26

View original

5 replies

Userlevel 7
Badge +21

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

Badge +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

Userlevel 7
Badge +21

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.

Badge +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..

Badge +3

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

Leave a Reply