If you don't care that the JS is added on every page, you might as well put it in hook_init. Otherwise if you want to use the same JS on multiple forms you would need multiple #after_build or #theme callbacks, which is repetitive and a little messy. Write your JS so that if indicative elements aren't present in the DOM it returns early.
On Wed, Mar 2, 2011 at 6:53 AM, Joel Willers joel.willers@sigler.comwrote:
I’m looking to do calculations between CCK fields. I’ve found some cool ways to add Javascript to a page, but before I get too far into this, I figured I’d ask for some quick advice to see if there was a better way.
Basically, I’m looking to do math on an ‘onchange’ event. If Field A is set (base) and Field B is changed, Field C and D automatically update. Similarly, if C changes, B and D update, and same for D changing B and C. I’m planning to use the technique described at:
http://switchbackcms.com/blog/right-way-include-javascript-your-drupal-form, but at http://drupal.org/node/322290 (#7) there is talk of adding a theme function, which I’m guessing I could do using a nice tpl.php file.
Any suggestions are welcome, especially if there is an already existing module for field relationships.
Joel
-- [ Drupal support list | http://lists.drupal.org/ ]