CakePHP and JavaScript onChange event

Posted by nikola, With 0 Comments, Category: CakePHP, Tags: ,

Here is example how to add onChange event in option-select (combo) form element.

$packages = array('1'=>'First', '2'=>'Second', '3'=>'Third'); // define some select-option element
// next will integrate onChange event into it
echo $form->input('package_id', array('options' => $packages, 'label'=>array('Package'), 'onchange' => "alert('Message!')" ));

Of course, $packages array can be defined in controller also (it's even better to be defined there).