Accessing Questions from other pages in wscScripting

When using wscScripting to interact with questions on the page you need to use the correct syntax to get the question
Reference Guide
On our Market Research Premium Edition and above you can access wscScripting to manipulate the content on the page and provide a totally customised experience for your respondents.

The first thing you will often need to do is get a Question Object with properties about the question. You do that by using the Question Access Code or sometimes called a Data Piping Code.

However, if you are accessing a question from a different page we need to tell WebSurveyCreator that we want to load the question, so that it's information is available.
The basic script to access a Question is as follows, where the Question Access Code for the question is "AGE"
var oQuestion = wscScripting.getQuestionByDataPipingCode('AGE');
This will allow you to get access to properties on the Question such as choices, rows, text and the type of the question.
However, if the question is not on the current page the use of the Question Access Code will not find the question immediately.

We need to also tell the system that we would like to have the question available

This process is similar to when we use Data Piping to access data from questions on previous pages and show the results on the current page.

We might have a question where we want to Data Pipe the answer to the "AGE" question. In data piping we would do the following:
On the previous page you stated your Age as [@AGE@]
When used as Data Piping the choice selected for "AGE" will be displayed to the respondent.

This process also ensures that the data for the question is available to the current page.

We can now use this same technique, with some adjustments, to ensure the question is available during scripting.
var oQuestion = wscScripting.getQuestionByDataPipingCode('[@AGE#data#@]');
The key point is we have used a valid Data Pipe but have embellished it with #data#. That is, if we have a valid Data Piping code that we could use anywhere else, we simply include the #data# prior to the final @]

Everything else stays the same as if the question was on the same page.
We are not loading the physical data like a data pipe would do. In the case of AGE the Age of the respondent will not be included in the script.

Entering this: -
var oQuestion = wscScripting.getQuestionByDataPipingCode('AGE');
Should be seen as being exactly the same as doing this:-
var oQuestion = wscScripting.getQuestionByDataPipingCode('[@AGE#data#@]');
except that the question is from a previous page.

In both cases, you will have a Question Object that you can use to determine properties of the Question.c/scripting-guide.aspx
For more information on wscScripting click here to see the complete scripting guide.
We recommend utilizing a tool such as the Chrome Dev Tools which will allow you to see the script and even test javascript in your web pages.

This will make it easier to determine the right script to use and also allow you to play with the scripts to obtain the best result.

The Chrome Dev Tools are perfect when testing your Custom Themes too.