Dynamic behavior for multiselect fields
It is possible to specify multiple answer options for multi-select fields. The user can select one or all options. The user may even revert an answer on the form. Bear in mind the way javascript works:
For contrasting answers, the Show function overrules the Hide function:
If (Option1) then hide (pss_fieldname_qq00000002); If (Option2) then show (pss_fieldname_qq00000002);
When a user changes answer options, the script runs its logic again from top to bottom:
If () then hide (pss_fieldname_qq00000002, pss_fieldname_qq00000003);
If (Green) then hide (pss_fieldname_qq00000002);
If (Blue) then show (pss_fieldname_qq00000002);
If (Blue) then hide (pss_fieldname_qq00000003);
If (Green) then show (pss_fieldname_qq00000003);
If the user first selects Green and then Blue also:
• Field qq00000002 is hidden and field qq00000003 is shown.
• Then field qq00000002 is shown and field qq00000003 is hidden.
Subsequently, after deselecting Green, field qq00000002 is shown and field qq00000003 is hidden (nothing appears to change).
Questions remaining visible
A pitfall with dynamic behavior is that initially hidden questions are shown when clicking a check box and may remain visible when the check box is cleared again.
For example, a form with a multi-select question:
Question | Specify cleaning area |
---|
Answer options | Room Kitchen Toilets Mail room Other room |
When "Room" is selected, another question "Specify room details" becomes visible:
Question | Specify cleaning area |
---|
Answer options | Room Kitchen Toilets Mail room Other room |
Question | Specify room details |
Answer options | A B C |
Additionally, selecting "Kitchen" for the first question also makes a third question "Specify kitchen details" visible:
Question | Specify cleaning area |
---|
Answer options | Room Kitchen Toilets Mail room Other room |
Question | Specify room details |
Answer options | A B C |
Question | Specify kitchen details |
Answer options | A B C |
Then when "Kitchen" is cleared, the question "Specify kitchen details" is expected to disappear but remains visible:
Question | Specify cleaning area |
---|
Answer options | Room Kitchen Toilets Mail room Other room |
Question | Specify room details |
Answer options | A B C |
Question | Specify kitchen details |
Answer options | A B C |
Although this looks like an error, this is specified behavior. This pitfall is common, but it can be prevented by applying a simple rule when creating the dynamic behavior script.
The first line of the dynamic behavior script should hide all the other questions that are influenced (show or hidden) by the question at hand - If (?) then hide (…)
The question mark ? represents an empty or any answer option, and the ellipsis (…) should be replaced by all questions that are affected. This way, only one simple 'If ' statement is required to hide the questions. It can also handle future added answer options.
This line performs a 'reset'. It means: if nothing or anything is selected, then hide the affected questions. After those lines questions can be made visible again by calling the Show function. This solution prevents issues as described in this section.