单选按钮选择更改Datepicker字段的值

时间:2016-10-04 13:36:32

标签: javascript yii yii2 radio-button active-form

我创建了带有三个单选按钮的表单,其值为window.printItn = function(myID) { 'use strict'; var printContent = document.getElementById(myID), windowUrl = 'about:blank', uniqueName = new Date(), windowName = 'Print' + uniqueName.getTime(), stylesheet = $('body').data('theme'), WinPrint; WinPrint = window.open(windowUrl, windowName, 'left=300,top=300,right=500,bottom=500,width=1000,height=500'); WinPrint.document.write('<' + 'html' + '><head><style type="text/css">@import "' + stylesheet + '";</style></head><' + 'body style="background:none !important"' + '>'); WinPrint.document.write(printContent.innerHTML); WinPrint.document.write('<' + '/body' + '><' + '/html' + '>'); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); }; $(".print").on('click', function() { printItn('YOUR-ID'); return false; }); YatimPiatu。我想选择值单选按钮Miskin以自动将“tanggal meninggal bapak”和“tanggal meninggal ibu”字段的值更改为Miskin
我试图使用JavaScript,但没有成功。我不知道为什么。

此视图/表单中的代码

0000-00-00

1 个答案:

答案 0 :(得分:0)

<?= $form->field($model, 'tanggal_meninggal_bapak')->widget(DatePicker::classname(), [
'options' => ['placeholder' => 'Masukkan tanggal meniggal bapak...', 'id'=>'bapak'],
'language' => 'id',
'pluginOptions' => [
    'autoclose'=>true,
    'format' => 'yyyy-mm-dd'
]
]); ?>
<?= $form->field($model, 'tanggal_meninggal_ibu')->widget(DatePicker::classname(), [
'options' => ['placeholder' => 'Masukkan tanggal meninggal ibu...', 'id'=>'ibu'],
'language' => 'id',
'pluginOptions' => [
    'autoclose'=>true,
    'format' => 'yyyy-mm-dd'
]
]); ?>


/*js*/
$("input[type=radio]").change(function() {
    var isi          = this.value;
    if(isi == "Miskin"){
       $('#bapak').val("0000-00-00");
       $('#ibu').val("0000-00-00");
       $("#bapak").attr("disabled",true);
       $("#ibu").attr("disabled",true);
    }
});