Drupal: Run simple JS Scripts on a specific node

User login

Let's say that you have a simple input form, on a specific node in your drupal site and you just want to reset it, using a button. There are a few ways you could go about it, but this one is probably the simplest one.
  1. Initialize global variable $base_url to gain access to functions base_path() and path_to_theme(), so that you can generate the script's path dynamically. ie
    <?php global $base_url; ?>
  2. Proceed to generate the right relative path to your script ie
    <?php print base_path().path_to_theme().'/js/myjs.js'?>
  3. Override the appropriate template file ie node.tpl.php
  4. You can now use your script's functions in the particular node ie
    <input type="submit" value="" name="op" OnClick="clrForm()">

<head>
    ...
    <?php print $scripts; ?>
    <?php global $base_url; ?>
    <script type="text/javascript" src="<?php print base_path().path_to_theme().'/js/myjs.js'?>">
</head>
Tags: 
Drupal 6, Drupal theming, Drupal Quick Tips