2

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'); 
1

1 Answer 1

1

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 https://drupal.stackexchange.com/ is a great resource if you haven't checked it out yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.