Attaching javascript events to form widgets

Posted by user334017 on Stack Overflow See other posts from Stack Overflow or by user334017
Published on 2010-05-18T01:58:56Z Indexed on 2010/05/18 2:00 UTC
Read the original article Hit count: 288

Filed under:

I have a form with a drop down menu and I want to do a javascript action whenever the user changes the selection. I imagine it is possible find the input later, using javascript, and attach an event to to it; but it seems like it would be easier if there was some sort of attribute or option that could be defined in form->configure(): e.g.

$this->widgetSchema['menu'] = new sfWidgetFormChoice(array(
  ...
  'onclick' => javascript function
));

obviously this doesn't work, and it probably wouldn't be an onclick method either, but my question is how do you attach a javascript event to a input/widget?

© Stack Overflow or respective owner

Related posts about symfony-1.4