I found a responsive menu code here and I want to add it to my Drupal 7 site. I have no experience with JavaScript, but I thought that if i just copy the script into mytheme/js/menu.js, call it in mytheme.info, and add the HTML to a block, I will have the script up and running.

The HTML part works fine, but the JavaScript part isn't working.

Why doesn't my JavaScript code work?

  • I have checked the provided link and I think, its for single page website. Do you want to create single page website? Jun 29, 2013 at 11:44
  • yes, thats what im trying to do. but for some reason the js doesnt do anything. Jun 29, 2013 at 12:35

2 Answers 2


Well adding JavaScript can be done through drupal_add_js().

You can add the JavaScript code in your template.php file.

  1. Create a cool.js file where you copy the JavaScript code
  2. Put the file in your themes/MYTHEME/js folder
  3. In your template.php file, create a page preprocess function

    function MYTHEME_preprocess_page(&$vars) {
      drupal_add_js(drupal_get_path('theme', 'MYTHEME') . "/js/cool.js", array("preprocess" => True));    
  4. Clear the cache

  5. Load your page and check the page source code to see if cool.js is being loaded; use ctrl+f to see if the file is present there

  6. If the effect is still not coming, then verify the IDs in the HTML are correct

  • i tried doing that, and this is what i got upon loading the page: Parse error: syntax error, unexpected $end in /home2/engeeoco/public_html/sites/all/themes/engeeo/template.php on line 16 Jun 29, 2013 at 11:28
  • You might have done something wrong in template.php. Please check your template.php code again. Sounds like you have not closed your function with }. Jun 29, 2013 at 11:32
  • hihi.. how embarrassing. yes i have no clue in php. anyway, site loads fine now, but still no java effect. you can see it here: engeeo.com Jun 29, 2013 at 11:35
  • I dint get you. Do you mean, you corrected the error ? Jun 29, 2013 at 11:36
  • i corrected the error, but now the javascript doesnt have any effect Jun 29, 2013 at 11:37

You can use Singe page website module to create single page website in the drupal 7.

You can check example for implementation of the module.

I have also checked your site engeego and I found that there is some javascript issue.

If you include javascript in drupal 7 theme, you need to enclose this into below function.

(function($) {

    //your code


Your Answer

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

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