====== getItemtext() ======

''string **getItemtext**(string //questionID//, int //item//)''

An item's or option's label can be determined with this function -- e.g. to use the text in another question or to display in the print view for the participant. The function can also determine the text in the question.

  * //questionID//\\ Question ID, e.g. "AB01"
  * //item//
    * <n> -- ID of an item in this question, e.g. 2 for item "AB01_02"
    * '''question''' -- Question's title
    * '''explanation''' -- Question's explanation

**Note:** It is often easier to use the function ''[[:en:create:functions:value|value()]]'' with  '''text''' or '''free''' as the second parameter (compare example 1).


===== Example 1 =====

In the following example, question "AB01" is a lengthier drop-down selection (on page 1 in the questionnaire). The respondent selects his favourite television program. The question is set so that the respondent must give a response. The title of the program will be shown in question "AB02". Thus, "AB02" has a placeholder ''%title%'' in the question title. 

In order for the placeholder to display the title, the selected title has to be identified initially with ''getItemtext()'' , and set up as placeholder with ''[[:en:create:functions:replace|replace()]]''. The following PHP code is put on page 2 or later on:


<code php>
$selection = value('AB01');  // respondent's selection (answer code = item)
$title = getItemtext('AB01', $selection);
replace('%title%', $title);  // set up placeholder
question('AB02');  // ask question AB02
</code>

The function ''[[:en:create:functions:value|value()]]'' can also be used with the respondent's free text input ("Other: ..."). Other than that, the following PHP code returns the same result as the PHP code above. 

<code php>
$title = value('AB01', 'free');  // Respondent's selection as text
replace('%title%', $title);  // Set up placeholder
question('AB02');  // Ask question AB02
</code>


===== Example 2 =====

At the end of the questionnaire, the participant should be shown his responses to selected items in question "AB02" (a fully labeled scale). The following PHP code determines the labels (item text) and responses (as text) for items 2, 4, 6 and 8, and displays this in a HTML table.


<code php>
$html = '<table cellspacing="0" cellpadding="2" border="1">';
foreach ($item in array(2,4,6,8)) {
  $itemtext = getItemtext('AB02', $item);
  $response = value('AB02_'.$item, 'text');
  $html.=
    '<tr>
       <td>'.$itemtext.'</td>
       <td>'.$response.'</td>
     </tr>';
}
$html.= '</table>';
html($html);
</code>