开发者

Attaching javascript events to form widgets

开发者 https://www.devze.com 2022-12-31 04:35 出处:网络
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

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
));

obv开发者_开发百科iously 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?


Every element that a form object creates should have an autogenerated id, which is usually in the form:

form_name_field_name

So how I do this, using jQuery as an example:

$('#form_name_field_name').change(function(){
  alert('do some cool stuff with '+this.val());
});


You can see it : How to use javascript in forms

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号