oTree Forum >

create an open-field

#1 by galbitton

Hi everyone, 

I want to create a variable that asks people for their ethnicity. This string variable gets 6 values for the different ethnic groups, another for "other", and the third for "refuse to answer". 

How can I attach to the value "other" an open field option so participant can write their ethnic group if clicking on "other"?

Appreciate your help!


#2 by gr0ssmann ,

The following "sketch" should give you a hint:

    <select onchange="select_change(this)">
        <option disabled selected>Please select:</option>
        <option>Option 1</option>
        <option>Option 2</option>
        <option>Option 3</option>
        <option>Prefer not to say</option>

    <div id="other_wrap" style="display:none">

        <input type="text" id="other_value" name="other_value" onchange="change_field(this.value)" />

    <input type="hidden" name="actual_field_name" id="actual_field_name" value="" />

        function select_change(el) {

            if (el.value == "Other") {
                document.getElementById("other_value").value = "";
                document.getElementById("other_wrap").style.display = "block";
            else {
                document.getElementById("other_wrap").style.display = "none";

        function change_field(val) {
            document.getElementById("actual_field_name").value = val;

Remember to replace actual_field_name with the field name defined in the Player class.

Write a reply

Set forum username