Hey, All
I am trying to create a row at the bottom of my side by side table that calculates the sum of each sub-column. Below is image of the side by side table.
Users will be putting in a number under each sub column in the Race/Ethnicity Column. I want the final row to calculate a total of that column. I am a novice at Java and have been using the following code:
Qualtrics.SurveyEngine.addOnReady(function()
{
var $jq = jQuery.noConflict();// always keep this
$jq('.SBS3 input[type="text"]').before('$'); //insert $ sign before boxes
$jq('.SBS1 select:last').hide(); // remove last select for Column 1
$jq('.SBS2 select:last').hide(); // remove last select for Column 2
$jq('.SBS3 select:last').hide(); // remove last select for Column 4
$jq('.SBS5 select:last').hide();
$jq('.SBS6 select:last').hide();
$jq('.SBS7 select:last').hide();
var $sum = 0; // define sum variable
$jq('.SBS4.c1 input:last').val($sum); // setting the value of total box
$jq('.SBS4.c1 input:last').css('fontWeight','bold') // setting fontface="bold"
//color change
if($sum>0){
$jq('.SBS4.c1 input:last').css('color','green');
}
else{
$jq('.SBS4.c1 input:last').css('color','red');
}
// setting the value 0 for all boxes if blank or 0
$jq('.SBS4.c1 input').each(function(){
$jq(this).val(getVal($jq(this).val()));
});
$jq('.SBS4.c1 input').keyup(function(){
$jq('.SBS4.c1 input').each(function(){
$jq(this).val(getVal($jq(this).val()));
});
});
//function for changing text value to numeric
function getVal(val){ var num = parseInt(val); if(isNaN(num)) { num = 0; } return num; };
// calculating some on keyup
$jq('.SBS4.c1 input').not(':last').keyup(function(){
// for every box
var $sum = 0; // define sum variable
$jq('.SBS4.c1 input').not(':last').each(function(){
$sum += +getVal($jq(this).val());
});
$jq('.SBS4.c1 input:last').val($sum);
//color change
if($sum>0){
$jq('.SBS4.c1 input:last').css('color','green');
}
else{
$jq('.SBS4.c1 input:last').css('color','red');
}
});
});
I can get it to total all of the sub_columns and the total appears under "White", but I am not sure how to translate that each sub column
Writing Script to create running totals of sub-columns in Side by Side Chart
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
