Hello i'm using CakePhp i'm trying to make a chained select with Ajax, the idea is that i make the jQuery action in the event onchange of the select input
onchange="TheFunction()";
but it seems like i have some syntax problém, the idea is that i send the value of the selected item to the function ShowProvider that searches for the providers that belongs to the selected category, and then sends it back to the callback function.
echo $this->Form->input('category_id',array('empty'=>'Selectionnez une','options'=>$categories,'class'=>'category','onchange'=>'
<?php
echo "
$.get(
//premier argument, le lien vers lequel on envoie les données
'. $this->Html->url(array('controller'=>'articles','actions'=>'ShowProvider'),true) .',
//2eme argument, on envoie l\'id de la catégorie selectionné
{id:$("select.category option:selected").attr("value")},
3éme argument
function(data){
alert("wssel");
}
)
"
?>
'));
here is the action ShowProcider()
public function ShowProvider(){
if ($this->request->is('ajax')) {
$result = $this->Article->Provider->find('list',
array('conditions'=>
array('category_id'=>$this->request->query['id'])
)
);
if ($result) {
$ret['name']=$result['Provider']['name'];
}
else{
$ret['name']='Vide.';
}
echo json_encode($result);
exit();
}
}
Thank's in Advance :)