cakePHP中选择框的onchange事件有问题

cakePHP中选择框的onchange事件有问题,cakephp,Cakephp,我在我的查看页面中编写了以下代码,用于自动填充选择框,其中包含课程中学生的名字和姓氏,并使用从下拉列表中选择的选项值自动填充名称文本框。但是在从列表中选择选项时不会自动填充名称。请帮助我解决此问题 $javascript->link('jquery-1.5.1.min.js'); $javascript->link(array('jquery', 'form')); $max_students = $this->Session->read('student_count')

我在我的查看页面中编写了以下代码,用于自动填充选择框,其中包含课程中学生的名字和姓氏,并使用从下拉列表中选择的选项值自动填充名称文本框。但是在从列表中选择选项时不会自动填充名称。请帮助我解决此问题

$javascript->link('jquery-1.5.1.min.js');
$javascript->link(array('jquery', 'form'));
$max_students = $this->Session->read('student_count');
$student_name = array(); 
$student_name[] = "-- Select --";
for($i=0;$i<$max_students;$i++)
{

    $student_first_name     = $this->Session->read('Student.'.$i.'.FirstName');
    $student_last_name  =$this->Session->read('Student.'.$i.'.LastName');
    $student_name[]         = ($student_first_name." ".$student_last_name);
}


$selectDomId = $this->Form->domId('students');
  $firstnameDomId = $this->Form->domId('Name');

  $this->Html->scriptBlock("
      jQuery(function($){
      $('#{$selectDomId}').change(function(event){
          $('#{$firstnameDomId}').val( $(this).val() );
            });
      });
  ",array('inline'=>false));


echo $this->Form->create('Contact',array('controller'=>'contacts','action'=>'addcontact'));
echo "<strong>Same As</strong>";
echo $this->Form->select('students',$student_name,$this->Form->domId(array(),'students'));
echo $this->Form->input('Name');

我真的没有太多的答案给你-但你能使用FireBug或某种等效的开发工具来找出当你改变select控件的值时是否有任何JavaScript错误被抛出吗?您还应该查看页面生成的HTML源代码,以确保正确生成脚本代码

尝试在JavaScript函数中插入调试语句,以确保调用也发生:

$this->Html->scriptBlock("
  jQuery(function($){
    $('#{$selectDomId}').change(function(event){
      $('#{$firstnameDomId}').val( $(this).val() );
    }); 
    alert('Test');
  });
",array('inline'=>false));