Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

Integrate second textbox showing a predefined value after scoring the question values

Valerie_K Community Member Qubie ✭
edited April 2 in Custom Code

Hello Qualtrics Community,

I am currently using code that enters a pre-specified value (defined in variable sum) into a textbox, which I thankfully got from another community member:

    var all_questions = [];
    var display_cal;
    document.querySelectorAll("div[id^=QID]:not(.Separator)").forEach((question) => {
        if (question.className.includes("TE")) {
            display_cal = question.querySelector("input");
        } else {

    display_cal.readOnly = true; = "not-allowed";

    function cal_sum() {
        var sum = 0;
        all_questions.forEach((question, which_q) => {
            question.querySelectorAll(".q-checkbox").forEach((chkbox, which_o) => {
                if (chkbox.className.includes("q-checked")) {
                    sum += Object.values(q_weights)[which_q][which_o];
        display_cal.value = sum;

where q_weights is a variable that was specified earlier in the code.

I now would like to use a second textbox on the same page, which displays a different value I would specify or alternatively adjust the textbox so that it shows the value of the sum variable as well as the newly specified variable I would call sum2.

In the second option, it would need to be apparent which value is which, i.e. the output should read something like:

"The finished product will cost $ sum.toString() and have sum2.toString() calories"

Is there a way to make this happen?

Thank you very much,