Translations of this page:
 

Placing input fields freely

You may wish to add a free text input field or a dropdown selection to a question.

Important: The question types “selection” and “multiple choice” provide this function by simply checking a box. See Free text inputs within a selection how to do this.

How to achieve a similar output with scales and other question types and how to provide a dropdown selection inside another question is described here. SoSciSurvey provides a special placeholder ​%input:…% for that purpose. We will guide you through using this function using the following example.

Example for freely placed input fields

Implementation

Actually, we merge different questions here. The example above shows a scale (question 1), one item from a text input question (question 2) and a dropdown selection (question 3).

Technically, the input field that is to be added has to be prepared with prepare_input(). In order to place the input field correctly, SoSciSurvey needs a placedholder amongst the original question's items. See further down for details.

First, the inputs to be used have to be created in the list of questions. That means you create a new question, for example a text input question. Second, a placeholder is created, consisting of ​%input:​, the ID of the question or item to be used (e.g., the ID of the text input field that you have just created), and finished by a ​%​. Insert this palceholder whereever the input shall appear.

Tip: Not every question type is available as independent input fields.

Mind methodological errors

There is a reason why extra text input fields cannot be added by default as it is with multiple choice questions: A text input field inside a scale (as above) is usually problematic or even unnecessary. No interview partner will enter something in the text input field and tell you “i never use this”. This usually makes the answers incomparable with the other scale question items. You may prefer adding a simple text input field “other:” underneath the scale: Concatenating Questions

Step by step

Create a new section with the ID “ZE”, and the Name e.g. “Freely placed input fields”.

Create the question ZE01 with type “text input”​. In this question, an item is added automatically, having the ID ZE01_01. For text inputs, it is useful to set their width – in this example 120 pixels. The item text will not show up, later. However set one, because it will be used for the variable lable in the data set.

Text input field that is to be placed freely

Create another question ZE02 with the type “dropdown” and add three choice options.

Dropdown selection to be placed freely

Now, create the question (ZE03) where the inputs shall be used within. In the above example, this is a “scale (fully labelled)” type question.

Example for freely placed inputs

Now we have to add placeholders into the question ZE03 (for more options, see placeholders in questions and items. To do so, we add two items with the text “other:” to the superior question's items and add the placeholders:

The first additional input field derives from item 01 of the question ZE01. The ID of this item is ZE01_01. The placeholder is made from this ID with a prefixed input: and a trailing percent sign: %input:ZE01_01%. So, add a new item to question ZE03 with this item text:

  Other: %input:ZE01_01%

Placeholder for input fields

The other input is a dropdown selection. For this one we do not use a single item, but the whole question ZE02. To do so, add another item to questiom ZE03, using the following item text:

  Other: %input:ZE02%

Example for freely places inputs

Optimization

An open-ended text input in a normal selection question automatically selects the appropriate option when the respondent writes something into the text field. When text inputs are placed using placeholders, they are not automatically associated with the corresponding option. This can be set up using JavaScript.

Extended Selection and Text

For example, if a question of the type “Extended Selection” (single or multiple choice) is used, insert the following JavaScript code (e. g. in an HTML code element) under the question.

<script type="text/javascript">
QuestionSelect.LinkSelect2Text("AU01_12", "TE01_01");
</script>

The first parameter in the function `QuestionSelect.LinkSelect2Text()` specifies the HTML ID of the radio button or checkbox, in the example the option with the code 12 in question AU01 (an extended selection that allows multiple choice selection). The second parameter is the HTML identifier of the corresponding text input (here the first input in question TE01).

The function `prepare_input ()` (in the PHP code at the top of the page) would have been used in this example for the identifier TE01_01.

If more than one open-ended inputs are used, you can simply call the function several times:

<script type="text/javascript">
new S2Selection.LinkSelect2Text("AU01_12", "TE01_01");
new S2Selection.LinkSelect2Text("AU01_16", "TE01_02");
new S2Selection.LinkSelect2Text("AU01_221", "TE01_03");
</script>

Selection and Dropdown

You have a dropdown within a selection (placed via placeholder) and the respective selection option shall automatically be selected when the dropdown is used?

This is accomplished by the JavaScript function QuestionSelect.linkOptionToInput(). The first parameter is the ID of the selection option (e.g., AB01_02 for the second option in the selection question AB01). The second parameter is the ID of the dropdown (or of a text input).

<script type="text/javascript">
new S2Selection.linkOptionToInput("AB01_02", "AB03");
</script>
en/create/inputs-single.txt · Last modified: 22.06.2019 15:29 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki