sgapiSetValue(%%questionID,%%value)

This function populates the response value of the given question. 

For hidden value, textbox, essay, radio button, drop-down menu, slider and image choice %%value is defined as a "string."

For checkbox and Drag & Drop %%value must be specified as an array.

To set the value of a list of dropdowns, radio button table, and checkbox table %%questionID should be specified as the ID of the table's row.

Examples

Check it out in an Example Survey

The following example will set the value of a question to be "yes." The question type could be text, essay, radio button, dropdown menu, or a hidden value action. If it is a radio button or dropdown, you need to make sure that it has the corresponding reporting value.

sgapiSetValue(2,"Yes");

Next let's set the value of a checkbox question. Let's say our checkbox question has reporting values "a", "b" and "c." Here, we tell our script to check the "a" and "c" options.

%%options = array("a","c");
sgapiSetValue(2,%%options);

For Drag & Drop Ranking questions you'll need to specify an array using the option skus like so:

sgapiSetValue(2,array('10001' => 4, '10002' => 3, '10003' => 2, '10004' => 1));

Limitations

  • sgapiSetValue cannot be used to set a value of an Admin Question on the same page. If you are using sgapiSetValue to set the value of an Admin Question it must be on a page that precedes or follows the script.
  • sgapiSetValue cannot be used to set the value of an other textbox