Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to add javascript to a single page. In php block code using the existing module

<?php 
   drupal_add_js('js/leagueSettings.js');
?>

I have a js folder in the modules/php directory where this specific module is.

I have tried using script tags also to no avail.

<script type = "text/javascript" src = "js/leagueSettings.js"></script>

leagueSettings.js is simply

(function ($) {
alert('here');
})(jQuery); 

I have tried it with only the alert..doesn't matter. I have tried using the DIR magic constant in place of the path.. nothing.

Anything I am missing?

EDIT---SOLUTION

//becuase the php block is 'php' module...
drupal_add_js(drupal_get_path('module', 'php') .'/js/leagueSettings.js'); 
share|improve this question
 
Where are you using drupal_add_js() in your code? As in, what function or hook? Also, be sure to read the documentation very carefully api.drupal.org/api/drupal/includes%21common.inc/function/… –  kevin628 Jun 12 '12 at 19:24

1 Answer

up vote 1 down vote accepted

the path js/leagueSettings.js is probably not working.

drupal_add_js(drupal_get_path('module', 'your_module_name')

If your js is in a module you can add it using the syntax above.

The same thing goes for <script> tag. the src needs to be correct.

also http://drupal.stackexchange.com/ is a great resource if you haven't checked it out yet.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.