I have made an ajax request to update the select options based on the first select field selection
but the respond only works fine with the first request despite being seen with firebug
help me solve it please
thanks in advance
here is the code
function listings_form_alter(&$form,&$form_state,$form_id){
$governments=array();
if($form_id == 'place_node_form' && arg(1)=='add' && arg(2)=='place'){
$vocabularies=taxonomy_get_vocabularies();
foreach($vocabularies as $vocab){
if($vocab->machine_name =='governorates'){
$_SESSION['vid']=$vocab->vid;
break;
}
}
$options=array(0=>'choose gov');
$g=taxonomy_get_tree($_SESSION['vid'],0,1,FALSE);
$x=count($g);
for($i=0;$i<$x;$i++){
$options[$g[$i]->tid]=$g[$i]->name;
}
$form['gov']=array('#title'=>'Gov','#name'=>'governorate'
,'#type'=>'select','#options'=>$options
,'#ajax'=>array('callback'=>'ajax_callback',
'event'=>'change','wrapper'=>'replace','method'=>'html'));
$op=array(0=>'choose city');
$form['city']=array("#title"=>'City','#name'=>'city',
'#type'=>'select','#prefix' => '<div id="replace">',
'#suffix' => '</div>','#options'=>$op);
function ajax_callback($form_state,&$form){
$childs_obj= taxonomy_get_children($_POST['governorate'],$_SESSION['vid']);
foreach($childs_obj as $child_item){
$op[$child_item->tid]=$child_item->name;
}
$form['city']=array("#title"=>'City','#name'=>'city','#type'=>'select','#prefix' => '<div id="replace">',
'#suffix' => '</div>','#options'=>$op);
return array(
'#type'=>'ajax', '#commands'=>array(ajax_command_html("#replace", render($form['city'])),
ajax_command_alert($_POST['governorate'])
)
); ?>