Questions, responses, and error messages
In terms of templates, a question consists of a banner, a question text (label), a response control, and an error message, which you can display anywhere and in any order on the page. The easiest way to display questions on a page is to place the following statement in the template at the point you want the question text to start:
<mrData/>
This displays the question text with the response control indented below it. If the respondent answers the question incorrectly, an error message is displayed above the question text.
The interviewing program inserts line breaks between the error message, the question text, and the response control.
If there is more than one question to display on the page, the questions and their respective response controls are displayed one after the other down the page.
If you want more control over the way the questions are displayed you will need to use the fuller form of the tag as shown below. You'll find more detailed descriptions and examples of using the individual attributes in the topics that follow. Note that while those topics generally deal with the attributes in isolation, you can include any combination of the listed attributes in a single instance of the tag if required.
<mrData [Index='number'] [QuestionElement='Qpart' [ShowErrors='Errtype']]
[AutoComplete='TrueFalse']> [Text] </mrData>
where:
▪number is a number that identifies individual questions on a page that needs to display more than one question.
▪Qpart specifies which part of the question to display at the current location and is one of:
Qpart
|
Description
|
Banner
|
Question banners
|
Controls
|
Response list or input box
|
Error
|
Error message
|
Label
|
Question text
|
Parameter
|
Information for a custom control. For more information, see Custom controls.
|
▪Errtype specifies which error messages to display for questions in loops and blocks and is one of:
Errtype
|
Description
|
All
|
All errors
|
BottomMost
|
Bottom level errors only
|
TopAndBottomMost
|
Top and bottom level errors
|
TopMost
|
Top level errors only
|
▪TrueFalse determines whether auto-completion is enabled for the question. This feature applies only to the Internet Explorer browser and is disabled by default.
▪Text is any text of your choice. The interviewing program ignores this text, but it is useful if you want to test your template by opening the .htm file in your browser or with a program such as FrontPage. In this case the text will be displayed in the position and with the attributes defined in the file.
Laying out the components of a question
Each question has four components: an optional banner defined in a separate information item, a text, a response list or input box, and, when appropriate, an error message. You can specify the positions of these components on the page by typing:
<mrData QuestionElement='Qpart']> [Text] </mrData>
where:
▪Qpart specifies which part of the question to display at the current location and is one of:
Qpart
|
Description
|
Banner
|
Question banners
|
Controls
|
Response list or input box
|
Error
|
Error message
|
Label
|
Question text
|
Parameter
|
Information for a custom control. For more information, see Custom controls.
|
▪Text is any text of your choice. The interviewing program ignores this text, but it is useful if you want to test your template by opening the .htm file in your browser or with a program such as FrontPage. In this case the text will be displayed in the position and with the attributes defined in the file.
For example, if you want to display error messages between the response control and the navigation bar you would place the following statements in the template file:
<mrData QuestionElement='Label'/>
<mrData QuestionElement='Controls'/>
<mrData QuestionElement='Error'/>
<mrNavBar>
If the respondent clicks Next without choosing an answer, the page that this template generates is:
Page showing repositioning of Error element
There are two things in this page layout that are not a result of the instructions in the template:
▪The response list is indented, while the template shows it in line with the start of the question and error texts. This is because the system default is to indent response controls. If you want the response control lined up with the left of the page, set the indentation to zero (or even to a negative value if necessary) by placing a statement such as:
IOM.DefaultStyles.Questions[..].Style.Indent=-1
in the routing section of the script. For more information, see
Indenting response lists.
▪The error message is in bold red type when nothing is specified in the template. This is the system default. If you want to change this you should do so in the interview script. For example, for purple, italic error messages you would type:
With IOM.DefaultStyles.Labels[LabelStyleTypes.lsError]
.Color = "#800080"
.Font.Effects = FontEffects.feItalic
End With
Displaying response controls side by side with question text
In some types of surveys you may want an interview page that looks like a form, with abbreviated question texts followed on the same line by selection or input boxes. If you just write a template that has the Label and Controls elements on the same line separated by spaces, the interviewing program will allocate as much space as it needs to each question text and will then append the response list or input box to the end of the line. Nothing will line up and the page may be hard to use.
One solution is to use a table; an alternative is to use interview scripting alignment features (see
Alignment and positioning) and to set a maximum width for the question texts in the script so that long texts are forced to wrap across lines.
Here is a simple form created using the following tags in the body of the template:
<table>
<tr>
<td><mrData Index="1" QuestionElement="Label"/></td>
<td><mrData Index="1" QuestionElement="Controls"/></td>
</tr>
Repeat definition for indexes 2 to 5
<tr>
<td><mrData Index="6" QuestionElement="Label"/></td>
<td><mrData Index="6" QuestionElement="Controls"/></td>
</tr>
</table>
Question texts and response boxes side by side
Additional points to notice about this example are:
▪The page displays six questions and the template defines positions for each question individually. This ensures that the question texts line up with their respective response controls. If you use a single
<mrData> tag for all questions and do not specify any alignment parameters in the script (see
Alignment and positioning), you may find that the question texts and response boxes do not line up because the boxes take up more vertical space than the texts. For further information about templates for displaying more than one question on a page see
More than one question on a page.
Automatic completion of data entry fields
The AutoComplete feature in Internet Explorer remembers texts and other values that you enter in web pages and then offers selected items as possible input for fields on other web pages. As you type information into a field, Internet Explorer compares the characters you type with the stored values and displays any entries that match. If the list contains the information you have started typing, you can select it from the list. If not, simply continue typing as normal.
This feature is turned off in the interviewing program, but you can switch it on and off as you want by placing the following statement in the page template:
<mrData AutoComplete='value'/>
where
▪value is either True or False.
For further information about AutoComplete, see your Internet Explorer online help.
More than one question on a page
When your script places more than one question on a page you have the choice of positioning some or all of the questions one by one, or of automatically placing them one after the other at a given starting point on the page. The default template uses the second method so that the questions follow one another down the page. To position the questions individually, use the QuestionName or Index attribute to refer to each question by name or according to its position in the set of questions for the page:
<mrData QuestionName='qname' [attributes]>
[text]
</mrData>
<mrData Index='number' [attributes]>
[text]
</mrData>
where:
▪qname is the question’s name.
▪number is a number that identifies individual questions on the page. Questions are numbered sequentially from 1 in the order they are named on the page statement.
▪attributes are any other attributes that can be used with <mrData> (typically, QuestionElement).
▪text is any text of your choice. The interviewing program ignores this text, but it is useful if you want to test your template by opening the .htm file in your browser or with a program such as FrontPage. In this case, the text will be displayed in the position and with the attributes defined in the file.
Example: Page with two rows of two questions each
For example, if the metadata section contains the statement:
demog "" page (gender, age, mstat, region);
and you want the page to look like this:
you would place the following statements in the template. Either:
<table>
<tr>
<td><mrData QuestionName="gender"/></td>
<td><mrData QuestionName="age"/></td>
</tr>
<tr>
<td><mrData QuestionName="mstat"/></td>
<td><mrData QuestionName="region"/></td>
</tr>
</table>
or:
<table>
<tr>
<td><mrData Index="1"/></td>
<td><mrData Index="2"/></td>
</tr>
<tr>
<td><mrData Index="3"/></td>
<td><mrData Index="4"/></td>
</tr>
</table>
In this example, the additional spacing between the columns has been achieved by setting the width of the question tag for the gender question in the interview script. For more information, see
Horizontal alignment.
Points to bear in mind when using this facility are as follows:
▪QuestionName and Index are interchangeable. In some respects, question names are better than indexes because it is immediately obvious which questions you are referring to. Also, if you insert extra questions, the index numbers will change and the template may no longer refer to the questions you expected. References to question names are not affected in this way. However, using question names ties the template to one set of questions. If you want to use the same layout for all pages with four questions, it is better to use index numbers.
▪Question names take priority over indexes, so if QuestionName and Index appear on the same <mrData> tag, Index is ignored.
▪If two <mrData> tags reference the same question in different ways, the question will be inserted at both locations.
The templates shown earlier have the same number of question names and indexes as there are questions to display, but it is good practice always to include a tag with no attributes at the end of the definition to catch any questions that are not represented by a named or indexed tag. This means that the template will still work even if the page statement names more questions than there are question names or index numbers. The layout will not be perfect, but you will generally pick this up while testing the script. If you do not define an empty tag, any extra questions will not be displayed, and you are less likely to notice this during testing. For example if the template contains:
<mrData QuestionName="age"/>
<mrData QuestionName="mstat"/>
<mrData Index="1"/>
<mrData Index="3"/>
<mrData/>
the rendered page will show age, mstat, gender, mstat, and region in that order.
Sub-templates for block and page questions
A question template that is applied to a block or page can contain multiple mrData Tags (the <mrData Index=”CCC”> attribute can be used). The Index attribute is supported by the mrData element in the LayoutTemplate.
Take the following metadata script as an example:
Metadata(en-US, Question, Label)
Disclosure "We do not disclose your personal details to anyone
outside our company."
info;
HowUseAnswers "The answers you give to the following questions
will be used for analysis purposes only."
info;
FirstName "What is your first name?"
text [1..20];
Job "What is your position in your company?"
categorical [1..1]
{
IntScriptwriter " Interview scriptwriter",
SMScriptwriter "Sample management scriptwriter",
SysAdmin "System administrator",
PhoneSupervisor "Phone room supervisor",
ProjMan "Project manager",
Interviewer "Interviewer",
Coder "Coder"
};
Age "How old are you?"
long [1 .. 200];
Demographics "Demographics"
page(
FirstName,
Job
);
End Metadata
The resulting Default Template.htm and Default Question Template.htm are:
<html>
<head>
…
</head>
<body>
…
<mrData Index="2" />
<mrData Index="1" />
<mrData />
<div><br/></div>
<mrNavBar />
</span>
</span>
</body>
</html>
and
<mrSubTemplate>
<mrData Index="1"/>
<mrData Index="2"/>
<mrData QuestionElement='Controls'/>
<mrData QuestionElement='Label'/>
<div><br/></div>
<mrData QuestionElement='Error' />
<div><br/></div>
</mrSubTemplate>
The routing script is defined as:
Routing(Web)
IOM.LayoutTemplate = "Default Template.htm"
Demographics.QuestionTemplate = "Default Question Template.htm"
Demographics.Ask()
Age.Ask()
End Routing
The rendered HTML contains the QuestionElement’s Control and Label elements, and well as the Question template’s Index element.
Error messages for questions in loops and blocks
When a respondent answers a question in a loop or a block incorrectly, there is usually more than one message that can be displayed. The default is to display messages related to the question itself, as shown in the following illustration, but you can display other messages as well:
Three-dimensional grid with messages for the repeated question only
The interviewing program generates one message related to the question itself and then a further message for each level of nesting, so the number of messages you can display depends on how deeply the question is nested. For example, if you have a loop that contains an inner loop, and the respondent incorrectly answers a question in the inner loop, there will be one message for the question and one for each of the loops, making three messages in all. You can use the ShowErrors attribute of the <mrData> tag to specify which messages you want to display:
<mrData QuestionElement='Error' ShowErrors='Errtype']> [Text] </mrData>
where:
▪Errtype is one of:
Errtype | Description |
---|
All | All messages. |
BottomMost | Messages for the question level only (the default). |
TopAndBottomMost | Messages for the question and outermost levels only. |
TopMost | Messages for the outermost level only. |
▪Text is any text of your choice. The interviewing program ignores this text, but it is useful if you want to test your template by opening the .htm file in your browser or with a program such as FrontPage. In this case the text will be displayed in the position and with the attributes defined in the file.
If you add the tag:
<mrData QuestionElement="Error" ShowErrors="All"/>
to the template and rerun the previous example, you will see an additional error message for the loop as a whole:
Three-dimensional grid with all messages displayed
See also