<div id="inner">
    <?php
    $optNum=0;
    if ($options && count($options)) {
        foreach ($options as $key => $value) {
            echo TbHtml::textFieldControlGroup("Choice[{$key}]", $value, array('label' => Yii::t('admin', 'Choice Number {number}', array("{number}" => $key + 1))));
              echo '<div class="float-right" id="first_op_'.$key.'">';
                echo CHtml::link('Delete this option', '#', array("onclick" => "remove_option_update($key); return false;")); 
                echo '</div>';
                $optNum++;
        }
    } else {
        echo TbHtml::textFieldControlGroup("Choice[0]", '', array('label' => Yii::t('admin', 'Choice Number {number}', array("{number}" => 1))),array('id'=>'group_0'));
        echo '<div class="float-right" id="first_op">';
        echo CHtml::link('Delete this option', '#', array("onclick" => "remove_option('Choice_0'); return false;")); 
        echo '</div><br>';
         $optNum=1;
    }
    ?>
</div>
<di>
<?php echo CHtml::link('Add another option...', '#', array("onclick" => "addAnotherChoice(); return false;")); ?>
</div>

<script >
    var currentFieldCount = <?php echo $optNum;?>;
    function addAnotherChoice() {
        var field = '<div class="form-group" id="group_#NUMBER"><label class="control-label" for="Choice[#NUMBER]">Choice Number #LABELNUMBER</label><div class="controls"><input class="form-control" type="text" value="" name="Choice[#NUMBER]" id="Choice_#NUMBER"></div><div class="float-right"><?php echo CHtml::link('Delete this option', '#', array("onclick" => "remove_option(#NUMBER); return false;")); ?></div></div>';

        field = field.replace(/\#NUMBER/g, currentFieldCount);
        field = field.replace(/\#LABELNUMBER/g, currentFieldCount + 1);
        $('#question_options #inner').append(field);
        currentFieldCount++;
    }

    function remove_option(currentField) 
    {
        if(currentField=='Choice_0')
        {
            // var select = document.getElementById('inner');
            // select.removeChild(select.childNodes[0]);
           $("#Choice_0").remove(); 
           $("label[for='Choice[0]']").remove();
            $("#first_op").remove();
        }else{

         $("#group_"+currentField).remove();
        }
        // alert(currentFieldCount);
        var rightOp=currentFieldCount-1;
        // alert('Choice_'+currentFieldCount);
        // var select = document.getElementById('inner');
        // var select = document.getElementsByClassName('Choice_rightOp');
        // var select = document.getElementById('Choice_'+currentFieldCount);
        // // select.removeChild(select.lastChild);
        //  select.removeChild(select);
       


       
    }

    function remove_option_update(currentField) 
    {
        // alert(currentField);
           $("#Choice_"+currentField).remove(); 
           $("label[for='Choice["+currentField+"]']").remove();
            $("#first_op_"+currentField).remove();  
            // $("#group_"+currentField).remove();
    }

</script>