Please state how long you have worked for this company.
from:%input:%ST17%
%input:%ST18%
to:%input:%ST19%
%input:%ST20%
The "to date" option has to be inserted as question. Either a line of PHP can be used to do so -- or drag the question onto the page and customize the display settings ({{:button.settings.png?nolink|Display Settings}}) slightly.
// Insert the alternative option ("to date") in the last cell
question('ST21','show-title=no', 'show-explanation=no', 'spacing=4');
==== Version 2 ====
Instead of working with placeholders, you can also insert all of the questions "normally". First of all, create the question title as well as the table framework:
Please state how long you have worked for this company.
The first dropdown input field (month in which the person started working) is now inserted with a line of PHP code -- or drag the question onto the page and customize the display settings ({{:button.settings.png?nolink|Display Settings}}) slightly.
The options in the ''question()'' command suppress the question text and explanations in question ST17; these will already be displayed with HTML code. The final option '''spacing=4''' states that there should only be a little bit of space underneath the input field.
question('ST17','show-title=no', 'show-explanation=no', 'spacing=4');
The HTML structure of the table now continues and each dropdown field is put between '' '' and '' '.
// Ask for first year in next cell
question('ST18','show-title=no', 'show-explanation=no', 'spacing=4');
// Ask for final month
question('ST19','show-title=no', 'show-explanation=no', 'spacing=4');
// End date: year
question('ST20','show-title=no', 'show-explanation=no', 'spacing=4');
// Insert alternative selection option ("to date") in the last cell
question('ST21','show-title=no', 'show-explanation=no', 'spacing=4');
==== JavaScript for "to date" Option ====
Now the questionnaire still has make sure the dropdown fields for the end date are disabled if "to date" was selected.
Insert the following JavaScript code as a text element (recommended) at the end of the questionnaire page, or as a HTML code element.
==== Check Input ====
If you want to install an additional consistency check in order to verify that a participant's input is sensible, do this with a filter on the __next__ page in the questionnaire ([[:en:create:checks#customized_response_check|Check Responses: Customized Response Check]]). In order to program this filter, you need the return values of your individual questions, which can be taken from the **Variables Overview**.
If you have created the questions as demonstrated in the examples, you will see the following:
* [ST17] and [ST19] respectively\\ 1 = January\\ 2 = February\\ ...\\ 12 = December\\ -9 = not answered
* [ST18] and [ST20] respectively\\ 1 = 2005\\ 2 = 2004\\ 3 = 2003 \\ ...\\ 35 = 1980\\ -9 = not answered
* [ST21]\\ 1 = not selected\\ 2 = selected
A filter is used to ensure that the date of leaving the company is always after the date of joining the company. In order to do this, ST19 has to accept a later month than ST18 if the person joined and left within the same year. As long as the year of leaving (ST20) is chronologically after the year of joining (ST18), the month is arbitrary.
In order to show the participant an error message and redisplay the question in these circumstances, create a text element in the **Text Elements and Labels** menu, which you can then use later on as an error message ("durationE" in the example).
// Year of joining is after year of leaving
if ((value('ST18') < value('ST20')) {
repeatPage('durationE'); // repeat previous page with error message
}
// In the same year, but different months
if ((value('ST18') == value('ST20')) and (value('ST17') > value('ST19'))) {
repeatPage('durationE'); // repeat previous page with error message
}