I have a DropDown list. I've written the code but it's not working. Please help me to fix it:
echo $form->field($model, 'Adrop')->dropDownList(
[
'' => 'Please Choose',
'1' => 'item 1',
'2' => 'item 2'
],
[
'onchange' => '$.post(Yii::$app->urlManager->createUrl . "users/A_action"), function(data) {
$("#test_div").html(data)
}'
]
);
Also I want to send selected data, and don't know where to write it.
In the Controller I have this action
public function actionA_action() {
$data = "TTT";
return $data;
}
Now when I select something in the DropDown list, nothing happens in my test_div
:(
UPDATE Thanks to Mihai P. now I'm using this code
<?php
echo $form->field($model, 'Adrop')->dropDownList(
[''=>'Please Choose','1'=>'item 1','2'=>'item 2'],
[
'onchange'=>'$.post( "'.Yii::$app->urlManager->createUrl(["users/A_action"]).'",function(data){
$("#test_div").html( data )
}']);
?>
The HTML is formed in the following way
<select id="A-adrop" class="form-control" name="A[Adrop]" onchange="$.post( "/users/A_action",function(){
$("#test_div").html( data )
}">
<option value="">Please Choose</option>
<option value="1">item 1</option>
<option value="2">item 2</option>
</select>
But when I choose something in debug this string is highlighted
<option value="2">item 2</option>
and there is one error saying
Uncaught SyntaxError: Unexpected token }
Final UPDATE
I've added one closing bracket on the last string of this code there are two of them closing now as you can see, and that was the problem. Semicolumn also will be a plus, but I've tested code works without it OK. problem was in closing bracket.
'onchange'=>'$.post( "'.Yii::$app->urlManager->createUrl(["users/A_action"]).'",function(data){
$("#test_div").html( data );
})']);