[Solved] GetValue from text box grid

0

Anyone know how to get values from a text box grid question? I have two rows of four text boxes each (which capture numeric values) and I would need values for the first two in the first row. Looked into documentation on this, but can’t quite make sense of the arrays described and how these would work for me.

Appreciate your help! 

Mihaly

MI asked

    Best answer

    0
    qc 558 Rep.

    Here’s the custom script I use when I need to total up the responses in a textbox grid question:

    %%grid_qid = 45;  // Question ID of the grid
    %%grid_colid = 10088; // Column or Option ID for the column you’re interested in (still needed if grid only has one column)

    %%total = 0;    // Initialize running total

    %%grid = sgapiGetValue(%%grid_qid); // Get an array of the responses to the grid question
     
    foreach (%%grid as %%rowid => %%rowarray) {   // Loop through each row in the grid
      %%total += %%grid{%%rowid}{%%grid_colid};   // Add the response to our running total
    }

    Adapting that, I think if you want to directly access the responses in Row1/Column1 and Row1/Column2, then you can try this (replace %%grid_qid, %%rowid1, %%colid1, %%colid2 with your actual question ID for the grid question, the question ID for the first row, and the option IDs for the first two columns):

    %%grid = sgapiGetValue(%%grid_qid);

    %%r1c1 = %%grid{%%rowid1}{%%colid1};

    %%r1c2 = %%grid{%%rowid1}{%%colid2};

    qc answered
      • Thanks a lot QC!

        This is the code I have now based on your suggestion. As I am not familiar referencing rows … does this look OK?

        %%grid = sgapiGetValue(%%271);

        %%r1c1 = %%grid{%%row-271}{%%10370};

        %%r1c2 = %%grid{%%row-271}{%%10371};

        function sgapiAddValues(%%r1c1, %%r1c2) {
        %%math = %%r1c1 + %%r1c2;
        return %%math;
        }

        Also, how do I save the result “%%math” to be able to pipe it into a new question?

        Like this?
        sgapiSetValue(511,%%math);

        Thanks a lot!

      • If 511 is your hidden value or where you are storing the number, then you have the right idea. :) (https://script.surveygizmo.com/help/article/link/sgapisetvalue). Cheers!

      ×

      Login

      Question stats

      • Active
      • Views2495 times
      • Answers1 answer
      • Followers0 followers