Hi,

I'm using Drupal 6.4 with a variety of modules to port my own home-grown site to Drupal. So far, things work nicely.
What I'm looking for now is a way to add javascripts to specific pages. These scripts don't do much more than take the values entered on the page and perform some calculations.
So far the only method I found was adding a line to the template linking in my own javascript file.

What I don't like about this method is:
1. I need to modify the template, which needs to be repeated every time the template is updated.
2. I need to modify the template for a non-template related issue.
3. the javascript file is loaded for EVERY page, not just the relevant ones.

Is there another way to make this work?

Thanks.

Comments

trevorleenc’s picture

this worked for me on some things...especially when calling jquery related scripts

http://api.drupal.org/api/function/drupal_add_js/5

hepabolu’s picture

This sounds like a good idea, but where do I add the line of code? To the page, to the theme? I can't figure that out from the description.

Thanks.

vm’s picture

on a specific page you would want to use inline, I believe:

Add inline JavaScript code ('inline'): Executes a piece of JavaScript code on the current page by placing the code directly in the page. This can, for example, be useful to tell the user that a new message arrived, by opening a pop up, alert box etc.

hepabolu’s picture

Searching on drupal_add_js gives the impression that it's added to the template. Which brings me back to my earlier disadvantages.

vm’s picture

custom tpl.php pages should allow you to do what you're after and won't be overwritten when the theme is updated as any tpl.php files you create won't be part of the package.

Michsk’s picture

- Create a new region, like region['js'] = Javascripts
- Place the region in page.tpl.php or any other .tpl.php page file within the .
- Add a block and place a page specfic javascript in it.
- Drag the block to the javascripts region and set it to only show on the page you want to use the javascript.

Probably not the best way but sure a good and working / simple way.