Hi,
I have a task where people have to solve some math questions. I want to create a variable which gives them 1 point for each right answer. The problem here is that, if they fill in the correct answer but accidentally press the space bar (before or after the correct answer, e.g.; 5), than the solution is considered wrong.
Is there a way to take into account spaces when building if conditions in the survey flow?
Thanks.
Stefano
What if you just disable space bar click for that particular container. As you would not be able to include space in the if branch logic.
Hope it helps!
Hi Deepak,
thanks. How do you disable space bar click?
https://community.qualtrics.com/XMcommunity/discussion/comment/52444#Comment_52444You can use the below code in JS to disable the space bar.
Qualtrics.SurveyEngine.addOnReady(function() {
document.onkeydown = function(event) {
console.log('keydown',event);
if (event.which == 32) {
event.preventDefault();
}
}
});
To enable:
Qualtrics.SurveyEngine.addOnReady(function() {
document.onkeydown = function(event) {
console.log('keydown',event);
if (event.which == 32) {
}
}
});
Hope it helps!
Thank you it worked! I have another question. Is there a way to force a single switching point in questions as the one reported below? Basically, I want people once the switch from option A to option B, to remain on option B for the consequent questions as well automatically:
Thanks
Stefano
Updating my response you can use something as below:
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var qid= this.questionId;
jQuery('#'+qid).click(function(){
var n= jQuery('td.c4.last').length;
var c = jQuery('table td.c4:even').length;
for (i=0; i
var b = jQuery('td.c4.last')[i].children[2].attributes[1].value;
if (b=='q-radio q-checked'){
jQuery('[id="QR~QID44~1~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~2~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~3~1"]').prop("disabled",true);
}
}
for (i=0; i
var d = jQuery('table td.c4:even')[i].children[2].attributes[1].value;
if (d=='q-radio q-checked'){
jQuery('[id="QR~QID44~1~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~2~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~3~2"]').prop("disabled",true);
}
}
});
});
Just change the QID and add for as many rows needed. I did for 3 rows your seems to be 10
Hope it helps!
Thank you Deepak. I am not very practical with javascript unfortunately. DoI have to substitute the question ID of my question only in the line "var qid= this.questionId"?
How do I add the 10 rows?
Moreover, Is this code actually displaying a single swtiching point or is it only saving data as they had a single switching point, even if a multiple swtiching point is displayed?
https://community.qualtrics.com/XMcommunity/discussion/comment/52509#Comment_52509I have updated the below to work it for the 10 rows. Preview of block
This is made where the scale points are 2 as per the picture attached by you.
You need to change the QID where I have commented below only the QID44 part. The code works in a manner where at start both decision options will be enabled but if the person chooses decision on option A all the radio buttons of option B will be disabled forcing them to choose option A for all.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var qid= this.questionId;
jQuery('#'+qid).click(function(){
var n= jQuery('td.c4.last').length;
var c = jQuery('table td.c4:even').length;
for (i=0; i
var b = jQuery('td.c4.last')[i].children[2].attributes[1].value;
if (b=='q-radio q-checked'){
/*Just change the QID44 part to your QID of the Question*/
jQuery('[id="QR~QID44~1~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~2~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~3~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~4~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~5~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~6~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~7~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~8~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~9~1"]').prop("disabled",true);
jQuery('[id="QR~QID44~10~1"]').prop("disabled",true);
}
}
for (i=0; i
var d = jQuery('table td.c4:even')[i].children[2].attributes[1].value;
if (d=='q-radio q-checked'){
/*Just change the QID44 part to your QID of the Question*/
jQuery('[id="QR~QID44~1~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~2~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~3~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~4~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~5~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~6~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~7~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~8~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~9~2"]').prop("disabled",true);
jQuery('[id="QR~QID44~10~2"]').prop("disabled",true);
}
}
});
});
Hope it helps!
This does the job almost perfectly, thanks! What I would like to have though it´s slightly different. I would like people to be able to choose between A and B at the beginning, but when they switch from A to B or to B to A, I want them to stick to the option the switched to for the rest of the table. Is this possible?
Thanks
https://community.qualtrics.com/XMcommunity/discussion/comment/52532#Comment_52532Stefano
If you just need to switch in first radio button you can use something like this
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var qid= this.questionId;
jQuery('#'+qid).click(function(){
var b = jQuery('table td.c4:odd')[0].children[2].attributes[1].value;
if (b == 'q-radio q-checked'){
/*Just change the QID44 part to your QID of the Question*/
jQuery('[id="QR~QID45~2~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~3~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~4~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~5~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~6~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~7~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~8~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~9~1"]').prop("disabled",true);
jQuery('[id="QR~QID45~10~1"]').prop("disabled",true);
}
else{
jQuery('[id="QR~QID45~2~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~3~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~4~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~5~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~6~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~7~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~8~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~9~1"]').prop("disabled",false);
jQuery('[id="QR~QID45~10~1"]').prop("disabled",false);
jQuery('td.c4:even>label')[1].className='q-radio';
jQuery('td.c4:even>label')[2].className='q-radio';
jQuery('td.c4:even>label')[3].className='q-radio';
jQuery('td.c4:even>label')[4].className='q-radio';
jQuery('td.c4:even>label')[5].className='q-radio';
jQuery('td.c4:even>label')[6].className='q-radio';
jQuery('td.c4:even>label')[7].className='q-radio';
jQuery('td.c4:even>label')[8].className='q-radio';
jQuery('td.c4:even>label')[9].className='q-radio';
}
var d = jQuery('table td.c4:even')[0].children[2].attributes[1].value;
if (d =='q-radio q-checked'){
/*Just change the QID44 part to your QID of the Question*/
jQuery('[id="QR~QID45~2~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~3~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~4~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~5~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~6~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~7~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~8~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~9~2"]').prop("disabled",true);
jQuery('[id="QR~QID45~10~2"]').prop("disabled",true);
}
else{
jQuery('[id="QR~QID45~2~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~3~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~4~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~5~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~6~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~7~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~8~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~9~2"]').prop("disabled",false);
jQuery('[id="QR~QID45~10~2"]').prop("disabled",false);
jQuery('td.c4:odd>label')[1].className='q-radio';
jQuery('td.c4:odd>label')[2].className='q-radio';
jQuery('td.c4:odd>label')[3].className='q-radio';
jQuery('td.c4:odd>label')[4].className='q-radio';
jQuery('td.c4:odd>label')[5].className='q-radio';
jQuery('td.c4:odd>label')[6].className='q-radio';
jQuery('td.c4:odd>label')[7].className='q-radio';
jQuery('td.c4:odd>label')[8].className='q-radio';
jQuery('td.c4:odd>label')[9].className='q-radio';
}
});
});
Change the QID as required.
Hope it helps!
This is a task that people in an experiment have to play. They can choose whatever they want. The only think I would like to have is that whenever they switch from A to B (it can be after the first radio button, or after the second, the third and so on), then they can only choose B thereafter. Thi is basically a consistency requirement.
For example, if someone chooses A in the first three radio buttons and then switches to B at the fourth one, I would like to have that from the fourth one on she/he can only choose B, or even better than B is compiled automatically thereafter. I would like this process to work not only for the example described but in general.
https://community.qualtrics.com/XMcommunity/discussion/comment/52537#Comment_52537The above code does it for the first row but according to you, there is no minimum after how many should the consistency begin it's just based on the switch of A to B hence, you will have to code differently and would require complex coding where every click will have to be checked and compared with previous one. Unfortunately, I wouldn't be able to help you with that.
Hope it helps!
thanks anyway.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.