使用javascript将div的内容附加到表单

时间:2018-02-01 13:17:37

标签: javascript forms yii2 append

我在div中有一个select表单元素,我想将该div的内容(select元素)附加到我的表单中。 我尝试了下面的代码,它的附加非常好,但是选择变为非活动状态,并且变更事件不再有效。 任何帮助将不胜感激谢谢。

//JAVASCRIPT CODE getting the div//
function getList(serial){
       return document.getElementById('selecter').outterHtml;
}
//Div Containing the SelectElement//
    <div id="selecter">

<?php
    $data = Arrayhelper::map(Goods::find()->all(), 'p_code', 'name');
// without model
echo Select2::widget([
    'name' => 'p_name[]',
    'data' => $data,
    'options' => ['placeholder' => 'Select Prroduct ...',
    'class'=>'form-control',
    'onchange'=>'
                    $.post( "index.php?r=goods/list&id='.'"+$(this).val(), function(data){
                    document.getElementById("eset").value = data;
                    });'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);?>
</div>
//End of Div//
onclick calls the getList function 

0 个答案:

没有答案