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

0

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? 

thanks

freestyle35 answered
    0

    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
      0

      There is an example of the difference between using sgGetValue and the JavaScript method in the SurveyGizmo API section of the documentation (https://script.surveygizmo.com/help/what-is-the-difference-between-custom-scripting-and-javascript).  In JavaScript you obtain the answer value thru the  element IDs  (https://script.surveygizmo.com/help/how-to-find-element-ids-to-use-with-javascript).

      The code and a working example of this method can be found in the documentation at https://script.surveygizmo.com/help/calculate-age

      Good luck!

      Jim W (Moderator) edited answer
        ×

        Login

        Question stats

        • Active
        • Views277 times
        • Answers2 answers
        • Followers1 follower