With a Likert, Single answer matrix question, I have limited the user to only having a maximum of 15 choices in the first column. This is done by Custom Validation.
To assist the user, I want to show them how many they have already selected from that column only.
I have found various JS tools that work for single answer questions and can adapt those to show me the "total selected", but I can't find a simple way to only count the selections from the first column!
Thank you all.
This is the sample code found on this site, (sorry can't find original post now), for simple question types:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var QID = this.questionId ;
jQuery("#" + QID + " input[type='checkbox']").on("click", function() {
var number = 0;
jQuery("#" + QID + " inputptype='checkbox']:checked").each(function(){
number=number + 1;
});
jQuery('#chkcount').text(number);
});
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Try changing this line:
jQuery("#" + QID + " td.c4 input[type='checkbox']:checked").each(function(){
I know this needs to be changed to
There is also change/ addition in td.c4
Hi rondev - I appreciate your help, but I am new to this and have close to zero understanding of JS. I know a bit of other languages.
What I need is the full list of methods and functions that can be used in Qualtrics. I have yet to find a resource that spells it out. From there I can teach myself.
Are you able to offer a more complete answer or suggestion?
Thank you again!
Here is the full working code:
var QID = this.questionId ;
jQuery("#" + QID + " input[type='checkbox']").on("click", function() {
jQuery('#chkcount').text(jQuery("#" + QID + " td.c4 input[type='checkbox']:checked").length);
});
Hello All,
Thank you for posting this code! I want to do something similar and have adpated it for the three questions I want to dynamically show "total scores" for. (I'm not counting the number of choices, but "scores" based on the values assigned to each of the choices--which I want to dynamically update before the respondents go to the next page.) However, I'm not able to get the score itself to show up in the descriptive text. I don't know any JS at all... could someone please help me figure out how to print it? THANK YOU :)
This is the code I have in the descriptive question that comes before the three single-answer MC questions that appear on the page:
Your current score is ${e://Field/eJStotalscore}
And here is the JS code I added to the descriptive question:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
jQuery("input[type=radio]").change(function() {
if(jQuery("#QID636 input.radio").is(":checked")){
var choiceNum1 = jQuery("#QID636 input.radio:checked").attr("choiceid");
var recodeMap1 = {"1" : 0, "2" : 100, "3" : 200, "4" : 300, "5" : 400, "6" : 500, "7" : 600, "8" :700, "9" : 800, "10" : 900, "11" : 1000};
var qScore1 = recodeMap1pchoiceNum1];
} else {
var qScore1 = 0;
}
if(jQuery("#QID653 input.radio").is(":checked")){
var choiceNum2 = jQuery("#QID653 input.radio:checked").attr("choiceid");
var recodeMap2 = {"1" : 10, "2" : 20, "3" : 30, "4" : 40, "5" : 50};
var qScore2 = recodeMap2 choiceNum2];
} else {
var qScore2 = 0;
}
if(jQuery("#QID644 input.radio").is(":checked")){
var choiceNum3 = jQuery("#QID644 input.radio:checked").attr("choiceid");
var recodeMap3 = {"1" : 0, "2" : 50, "3" : 100, "4" : 150, "5" : 200};
var qScore3 = recodeMap3qchoiceNum3];
} else {
var qScore3 = 0;
}
var qScore = qScore1 + qScore2 + qScore3
jQuery("#totalscore").html(qScore);
jQuery("#totalscore").text(qScore);
Qualtrics.SurveyEngine.setEmbeddedData("eJStotalscore",qScore);
});
});
https://www.qualtrics.com/community/discussion/comment/24616#Comment_24616Hi there Ron,
Just curious about the dynamic aspect of this. I've got it to work with an embedded variable, but it will only display on the next page. Is there a way to get it to 'stream live'? Will embedded variables work for this? or is there another thing that I'm missing?
Thanks!!
jess
https://www.qualtrics.com/community/discussion/comment/26239#Comment_26239Yes, on every click click you can set/ update the embedded data value,something like below:
var QID = this.questionId ;
jQuery("#" + QID + " input[type='checkbox']").on("click", function() {
var s = jQuery("#" + QID + " td.c4 input[type='checkbox']:checked").length;
jQuery('#chkcount').text(s);
Qualtrics.SurveyEngine.setEmbeddedData("ED1", s);
});
https://www.qualtrics.com/community/discussion/comment/26240#Comment_26240Thank you!
This what I have:
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("#" + this.questionId +" .c2").hide(); //hiding these for CSS formatting reasons.
jQuery("#" + this.questionId +" .c3").hide();
jQuery("#" + this.questionId +" .c4").hide();
jQuery("#" + this.questionId +" .c5").hide();
jQuery("#" + this.questionId +" .c6").hide();
jQuery("#"+this.questionId+" .ReadableAlt").css("background","#F6F6F6"); //alternate color
var QID = this.questionId ;
jQuery("#" + QID + " inputttype='radio']").on("click", function() {
var s = jQuery("#" + QID + " td.c7 inpututype='radio']:checked").length;
jQuery('#chkcount').text(s);
Qualtrics.SurveyEngine.setEmbeddedData("Count_col0", s);
});
});
And then I have tried embedding the variable (Count_col0) in the Question Text and in the Column header with no luck. It only works on the next page. Did I do something wrong?
JMaca - you need an element with the id chkcount in your question text:
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.