Skip to main content
Skip table of contents

jsAPI examples

Send data from one page to another.

On many occasions, when the form/survey consists of multiple pages, there might be a need to execute some logic based on the answers to the previous question(s). The feature called Piping is used to maintain the state across multiple pages.

On the input side of piping, the following JavaScript code needs to be added to the Scripts page of the form/survey:

CODE
ksAPI.runAfterActions(function() {
    if (vpGetResults("Q2.A1").length === 0) {
        vpSetResults("Q2.A1", vpGetResults("Q1.A1")[0].value);
    }
});

Consequently, on the receiving end of piping, the following code in start() function is needed in order to read the information and call appropriate logic in functions f_q7() and f_q18() based on it:

CODE
function start(pipe_in) {
...
  if ( pipe_in[0] != "") {
     f_q7();               
  }
  if ( pipe_in[1] != "") {
     f_q18();              
  }
...
}

Here is another example of piping used to copy address fields from one page of the form/survey to another:

CODE
function Pipe()
{
  var name='{Q3.A1}';
  var phone='{Q3.A3}';
  var address='{Q3.A5}';
  var city='{Q3.A6}';
  var state='{Q3.A7}';
  var zip='{Q3.A8}';
  vpGetElements("Q23.A1")[0].value=name;
  vpGetElements("Q23.A2")[0].value=phone;
  vpGetElements("Q23.A3")[0].value=address;
  vpGetElements("Q23.A4")[0].value=city;
  vpGetElements("Q23.A5")[0].value=zip;
  vpGetElements("Q23.A7")[0].value=state;
}
  
jQuery(document).ready(function () {
  if (vpGetElements("Q23.A1") !=null) {
    Pipe();
  }
});  
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.