So jquery’s  $(document).ready() isn’t working for you in Drupal 6. Dont worry. It’s not an error on your part, and very easy to troubleshoot.

The reason for this behaviour is that $(document).ready() doesn’t exist in drupal. The reason for this is very simple. There can be only one document.ready function, and Drupal is already using it. Instead you must use Drupal’s built in hook to document.ready. So instead of this javascript:

$(document).ready(function() {
// put all your jQuery goodness in here.
});

Use this Javascript in your Drupal template file (e.g. page.tpl.php):

Drupal.behaviors.myModuleBehavior = function (context) {
// put all your jQuery goodness in here.
}

myModuleBehavior just needs to be a unique name, and is right off the top of my head.

Of course this doesn’t accept any variables (context is a fixed Drupal variable and cannot be changed), so add variables to it following this pattern via PHP code:

drupal_add_js(array('myvariable' => 'test'), 'setting');

and access them as such in your Javascript:

Drupal.behaviors.myModuleBehavior = function (context) {
 alert(Drupal.settings.myvariable);
}

Enjoy!