CakePHP onChange事件

时间:2011-11-23 04:24:28

标签: html cakephp onchange

我不知道为什么这个onChange事件无效。也许我已经习惯了代码,我看不出自己的错误。我很感激你的帮助:

<td class="cellInput">
  <?php
    $options = array('200'=>'200', '500'=>'500', '1000'=>'1000', '2000'=>'2000', '5000'=>'5000', 'Outro'=>'Outro');
    $attributes = array('legend' => false);

    echo $form->select('capacidade', $options, array(
      'class' => '',
      'label' => '',
      'default' => '200',
      'onchange' => "javascript:checkForOther(this);",
    )); 
  ?>
</td>

3 个答案:

答案 0 :(得分:2)

正如其他人建议的那样,将属性放在正确的参数位置。我要做的另一件事是删除javascript并在其中只有函数名称:

来自:'onchange' => "javascript:checkForOther(this);"

收件人:'onchange' => "checkForOther(this)"

答案 1 :(得分:0)

尝试

  1. 将属性作为第四个参数而不是第三个参数:

    echo $form->select('capacidade', $options, null, 
        array(
            'class'=>''
            ,'label' => ''
            ,'default' => '200'
            ,'onchange' => "javascript:checkForOther(this);"
        )
    );
    
  2. 生成的页面的源是否具有onChange属性?

  3. 请参阅documentation

答案 2 :(得分:0)

根据CakePHP documentation on select method,第三个参数用于选择默认选择的选项。

您必须使用第四个参数将HTML属性传递给select元素:

<td class="cellInput">
  <?php
  $options = array('200'=>'200', '500'=>'500', '1000'=>'1000', '2000'=>'2000', '5000'=>'5000', 'Outro'=>'Outro');
  $attributes = array('legend'=>false);
  echo $form->select('capacidade', $options, '200', array('class'=> '', 'label' => '', 'onchange' => "checkForOther(this);")); 
  ?>
</td>