Dependent YII Input Box? Where is my Mistake? How to add Onchange Event in dropDownList? I don't know how to add event in dropdown list.
View :
<div class="row">
<?php echo $form->labelEx($model,'payment_method'); ?>
<?php echo $form->dropDownList($model,'payment_method',array("Select","bank"=>"Bank","cash"=>"cash", onChange= 'javascript:myFunction()')) ?>
<?php echo $form->error($model,'payment_method'); ?>
</div>
<p id="demo"></p>
Java scrip :
<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>
You scripts contain syntax error. In you script onChange=
should be 'onChange'=>
and add a ;
at the end of the same line. Change the line and try again
<?php echo $form->dropDownList(
$model,
'payment_method',
array(
"Select",
"bank"=>"Bank",
"cash"=>"cash",
),
array(
'onChange'=> 'javascript:myFunction()',
'id'=>'mySelect'
)
); ?>