[development] Drupal way of doing onchange

James Gilliland neclimdul at gmail.com
Sun Nov 22 18:53:09 UTC 2009


AHAH is generally more for submitting something and changing the form,
this doesn't really sound like your example. ie. submitting a file
like in the d.o issue queue.

Generally the "Drupal way" is the jQuery way in the simple case you
described. It doesn't add javascript directly to anything html
elements and uses the jQuery event handlers in a javascipt file added
to the page. This ends in much more manageable code, less html, etc.

http://docs.jquery.com/Events/change

On Sun, Nov 22, 2009 at 12:37 PM, Jeff Greenberg <jeff at ayendesigns.com> wrote:
> Haven't delved into AHAH yet, this might force the issue.
>
>
> Using an easy (=less typing) example. A credit card form. When the credit
> card type is selected from a select, the selection needs to fire a
> javascript function that will disable fields that don't apply to that card
> type (such as CVV).
>
>
> Normally, I would have an onchange event for the select, and noticed that in
> the form api, while there is an attribute section to add miscellaneous
> attributes, the doc doesn't mention events as examples. And if putting an
> event there is legitimate, there isn't a mention of how to include the
> responding js function in the form.
>
>
> If AHAH is the way I'm supposed to handle this, I'd appreciate being pointed
> to a good similar example, because I'm a bit unclear from the AHAH entries
> in the form reference docs, for example, how to relate the myhandler/js
> entry to a physical location of the function, and how the function gets
> there.
>
>
> Thanks!
>
>


More information about the development mailing list