0

以下 jquery ajax 代码适用于 #MerryParentEmail keyup 事件,但不适用于 #MerryParentState 更改事件。更改事件正在触发,但城市下拉框未填充。

<script type="text/javascript">
  $(document).ready(function(){
         $("#MerryParentStateId").change(function(){
        state=$(this).val();
        txt_str="state_id="+state;
        $.get("../students/getcities",txt_str,function(result){
            $("#MerryParentCityId").html(result);
        });
     });

 });

</script>

student_controller.php

   function getcities(){
    $options = $this->Student->MerryParent->City->getCities($this->data['MerryParent']['state_id']);
    print_r($options);
    foreach ($options as $k=>$v){
        echo '<option value="'.$k.'">'.$v.'</option>';
    }

}

添加.ctp

<?php
echo $this->Session->flash();

echo $this->Form->create('Student');
echo '<fieldset>';
echo '<legend>Student Information</legend>';
echo $this->Form->input('Student.name');

$options = array('Male'=>'Male','Female'=>'Female');
$attributes = array('value'=>'Male');
echo $this->Form->radio('Student.gender',$options,$attributes);

echo $this->Form->input('Student.dob', array('label'=>'Date of Birth',
                'dateFormat'=>'DMY', 
                'empty'=>'Choose one',
                'timeFormat' => '', 
            'minYear' => ( 
                    date('Y') - 5 
            ), 
            'maxYear' => ( 
                    date('Y') - 2 
            ) 
            ));
echo $this->Form->input('Student.merry_class_id', 
        array(
        'label'=>'Enquiry Class for',
        'empty'=>'Choose one',
        'options'=>array('1'=>'Playgroup','2'=>'Nursery','3'=>'LKG', '4'=>'UKG')
        )
        );

echo '</fieldset>';

echo '<fieldset>';
echo '<legend>Parent Information</legend>';
//echo $form->input('Student.parent_id', array('type'=>'hidden'));
echo $this->Form->input('MerryParent.initial', 
array('empty'=>'Choose one',
'options'=>array('Dr'=>'Dr', 
                'Mr'=>'Mr', 
                'Mrs'=>'Mrs', 
                'Ms'=>'Ms')
)
);
echo $this->Form->input('MerryParent.email');
echo $this->Form->input('MerryParent.name', array('label'=>'Parent/Guardian Name'));
echo $this->Form->input('MerryParent.landline');
echo $this->Form->input('MerryParent.mobile');
echo $this->Form->input('MerryParent.address');
echo $this->Form->input('MerryParent.state_id', array('empty'=>'Choose one','options'=>$states));
echo $this->Form->input('MerryParent.city_id');
echo $this->Form->input('MerryParent.postal_code');
echo '</fieldset>';

echo $this->Form->end('Submit');
 ?>
4

2 回答 2

0

当我修改 student_controller.php 中的 getcities 函数以包含

$this->data['MerryParent']['state_id']=$_GET['state_id'];

城市下拉框正在填充所选州的城市。

因此,以下是修改后的 getcities 函数:

function getcities(){
    $this->data['MerryParent']['state_id']=$_GET['state_id'];
    if (!empty($this->data['MerryParent']['state_id'])){
       $cities = $this->Student->MerryParent->City->getCities($this->data['MerryParent']['state_id']);
    //print_r($cities);
    foreach ($cities as $k=>$v){
        echo '<option value="'.$k.'">'.$v.'</option>';
    }

        /* foreach($cities as $optionValue){
            echo '<option>' . $optionValue . '</option>';
        }*/
    }else{
        $this->Session->setFlash('You didn\'t select a state!');
    }

}

谢谢你。

于 2012-04-10T03:41:07.020 回答
0
function formatosDinamicos(){
$id_a = $_GET['agente_id'];
if(!empty($id_a)){
    $listaFormato = $FormatoController->listaVariableFormatoDependent($id_a);
    foreach ($listaFormato as $k=>$v){ 
        echo '<option value="'.$k.'">'.$v.'</option>'; 
    }
}else{
    $this->Session->setFlash('Error!');
}
$this->autoRender = false;
}

在函数 autoRender 的按钮中为 false

于 2013-09-03T19:36:24.410 回答