If you don&#39;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&#39;t present in the DOM it returns early.<br clear="all">
<div><br></div><div class="gmail_quote">On Wed, Mar 2, 2011 at 6:53 AM, Joel Willers <span dir="ltr">&lt;<a href="mailto:joel.willers@sigler.com">joel.willers@sigler.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p><p class="MsoNormal">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:</p>
<p class="MsoNormal"><a href="http://switchbackcms.com/blog/right-way-include-javascript-your-drupal-form" target="_blank">http://switchbackcms.com/blog/right-way-include-javascript-your-drupal-form</a>, but at <a href="http://drupal.org/node/322290" target="_blank">http://drupal.org/node/322290</a> (#7) there is talk of adding a theme function, which I’m guessing I could do using a nice tpl.php file.  </p>
<p class="MsoNormal"> </p><p class="MsoNormal">Any suggestions are welcome, especially if there is an already existing module for field relationships.</p><p class="MsoNormal"> </p><font color="#888888"><p class="MsoNormal">
Joel</p><p class="MsoNormal"><b><span style="font-size:7.5pt;color:gray"> </span></b></p><p class="MsoNormal"> </p></font></div></div><br>--<br>
[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br></blockquote></div><br>