====== Observational Study Counter ====== SoSci Survey can also be used -- on a tablet, for example -- to assist observers in observational studies or coders in content analyses of video footage. The following instructions explain how to program a questionnaire page on which several buttons are offered. If one of the buttons is clicked, the counter for the corresponding event is increased by 1. {{:de:create:exp.observation-counter.png|Result}} The questionnaire page contains five elements, which are explained below. ==== JavaScript-Code to Count ==== Ror the counting a little bit of JavaScript is needed. This code consists of two parts. One is a function ''count()'' which initializes or increments by one the value in the form field specified by an HTML ID. Second, a small JavaScript object ''ButtonCounter()'', which takes an HTML ID for a form field and a button, respectively. The object initializes the form field with the previously defined ''count()'' function and registers the JavaScript event handler, which responds to clicks. Create a **New Text** in a section in the questionnaire (here in the example "JS"), set as *Display* "HTML Code" and insert the following JavaScript code. After saving, drag the text element under **Compose Questionnaire** as the first element on the questionnaire page. ==== CSS Code for Formatting the Buttons ==== In principle, the ''
Important is the (unique) identifier in the ''id'' attribute (''button01'', ''button02'', ...), which is freely selectable and needed below. The ''%%class="js"%%'' ensures that the CSS is applied from above. The ''
'' only provides a graphic separation from the following question. ==== The Form Elements ==== In order for SoSci Survey to store the count data in the dataset, create a question of type "Open Text Entry" or "Internal Variables" in the **Question Catalog** In the example above, an open text input was chosen so that one can follow the current state of the count live and correct it if necessary. The value 60 was entered as the width for the "Input column" in the question under //More settings// -> //Display// -> //Texte input field// -> //Column//. Furthermore, the input format for all input fields has been restricted to "Integers" so that the variable in the data set uses a numeric data type. Both adjustments are not necessary, but quite helpful. Create an item or variable for each button in the question. In the example above, these are 4 items that have the same label as the 4 buttons, so that the labeling in the data set is correct. This question is inserted as the fourth element (or anywhere else) on the questionnaire page. ==== Initialize the JavaScript-Object ==== Finally, the JavaScript objects defined at the beginning must be initialized. The object links the HTML IDs of the form elements (input fields from the questions) with the HTML IDs of the buttons. A ''new ButtonCounter()'' is required per button here. The first parameter is the HTML ID of the form element (text input field or internal variable), the second parameter is the HTML ID of the button, as specified in the HTML code above. This JavaScript code is inserted into an element "HTML Code", which is placed as the fifth element on the questionnaire page.