Using Checkbox answers in Scripting

0

Hello, I think I’ve mastered using logic in scripts with radio buttons answers, but I just cannot figure how to do it with Checkboxes.

So, I have a radio button question and I can write….

if (sgapiGetValue(%%radiobuttonquestion) == “blahblah” )
{
sgapiSetValue(%%targetvariable,”yes”);
}

But what is the equivalent with Checkboxes? I would like something that says “if they tick this box then do that” but after three or four hours I still can’t get it. It probably has something to do with In_Array and sgapiPrint_R(sgapiGetValue(xxx)), but all I can do is extract the entire array

Array(    [10213] => blahblah)

What I really want to write is something like

if ((sgapiGetValue(%%thecheckboxquestion, option row 3) == “blahblah”) 
{
sgapiSetValue(%%targetvariable,”yes”);
}

Please Help!!

 

Justin Worsley answered
    0

    I’ve sorted this now, many thanks to those who looked in….

    The first step is to get the array, this is done with sgapiGetValue, in my case:

    sgapigetvalue(5)

    which returns an array from Question ID 5, which in my case is

    Array(    [10001] => run    [10002] => jump)

    The second step is to extract the reporting value within the array you want access to, which in my case was the word “jump”

    The function here is called sgapiArrayGet

    This has a syntax as follows:

    sgapiArrayGet(an array, the id of the option you want)

    It has an output value of the reporting value of just that id option.

     

     

    Putting the two bits together you get

    sgapiArrayGet(sgapiGetValue(5),10002)

    which returns the word “jump”

     

    I then used that result in a conditional statement: if the checkbox says jump then you say “how high”

    If (sgapiArrayGet(sgapiGetValue(5),10002)==”jump”)
    {
    sgapiSetValue(“jumpaction”,”how high?”);
    }

     

     

     

     

     

     

     

     

     

     

    Justin Worsley answered
      0

      Hi, I appreciate your reaching out, but I’m fraid it is not really working for me…

      If I put in..

      sgapiSetValue(99,(sgapiGetValue(96)));

      I get a blank response (id=96 is a checkbox)

      So I add the sgapiPrint command as advised:

      sgapiSetValue(99,sgapiPrint_R(sgapiGetValue(96)));

      and I get a response, albeit packed inside an array:

      Array(    [10213] => prefer others)

      But when when I try to add options…

      sgapiSetValue(99,sgapiPrint_R(sgapiGetValue(96,option(10213))));

      I get Bad Syntax, like the (questionid, option(id)) syntax is wrong.

      Driving me crazy!

      Justin Worsley answered
        0
        IS 2.20K Rep.

        You need to find the option ids. There is some help with that here:

        https://help.surveygizmo.com/help/how-to-find-ids

         

        Then your if statement will look something like:

        if ((sgapiGetValue(%%thecheckboxquestion, option(nnnnn) == “xxx”) 
        {
        sgapiSetValue(%%targetvariable,”yes”);
        }

        Where nnnnn is the option ID and xxx is the reporting value for that checkbox.

        IS answered
          ×

          Login

          Question stats

          • Active
          • Views5723 times
          • Answers3 answers
          • Followers2 followers