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
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
Please Choose
item 1
item 2
But when I choose something
in debug this string is highlighted
item 2
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 );
})']);