How do I retrieve the answer to a question using JavaScript?


This is not made clear anywhere in the documentation. sgapiGetValue is part of their PHP-like API but unless I’m missing something, that function is not available using Javascript. Merge codes are easy to use w/ PHP scripting but what’s the equivalent in JavaScript? 


freestyle35 answered

    This gap in the SG scripting capability still doesn’t have a solution (or if there is one, I can’t find it). Basically, I need the ability to modify HTML on each page based on an answer to a question or URL variable passed in. Here’s a possible way for SG to provide this capability:

    1. Short PHP custom scripting, ascertain a URL variable value at the beginning of a survey
    2. assign the value of the URL variable to an persistent data object (PDO); PDO would be a new type of data the survey builder could add to the survey
      • PHP (SG scripting) could make this easy since it runs server side. I could get the value of the URL variable.
      • But, I need to be able to define a new object in SG called something like ‘Persistent Data Object’ and give it a name
      • I could use custom scripting to assign the data object a value but the server side code behind Survey Gizmo would need to make this object’s value available on each page. JavaScript runs client side and could access a hidden input field. The SG engine would simply need to create the ‘<input type=’hidden’ id=’id specified in survey build interface’ value=’default value that could be over ridden’/>.
    3. I could create a script in the <head> of each page that could manipulate the page based on the value of the persistent data. For example, I could modify the footer logo on each survey page to be the logo of the medical practice that’s passed in using a URL value.

    I can talk through this with a developer but I think it would be pretty straight forward to implement. This would be a great enhancements to your scripting capabilities by providing a mechanism to connect server side scripting capabilities (PHP) to client side (JavaScript)

    What are the chances of getting something like this added?


    freestyle35 answered

      The first link makes a statement that I had overlooked but it’s very important: “Custom Scripting runs server side and JavaScript runs client side.” The doc should point out one very important distinction and limitation to JavaScript in SurveyGizmo. Server-side gives you access to what’s on the server (e.g. questions and other meta data for any question on any page). This is made simple using merge-codes. Client-side limits your access to what’s loaded on the current page. JavaScript does have server-side capabilities (e.g. using the very friendly jQuery API around AJAX but SurveyGizmo hasn’t implemented this). Bottom line: if you want to access information from prior pages, it’s best to use scripting (PHP). You could put together a clunky JavaScript solution but storing the info you want in a hidden value on the current page, then getting that element id, etc… but that’s a bit of a kludge.

      thanks for the info

      freestyle35 answered

        There is an example of the difference between using sgGetValue and the JavaScript method in the SurveyGizmo API section of the documentation (  In JavaScript you obtain the answer value thru the  element IDs  (

        The code and a working example of this method can be found in the documentation at

        Good luck!

        Jim W (Moderator) edited answer


          Question stats

          • Active
          • Views15020 times
          • Answers3 answers
          • Followers2 followers