Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:09:46+00:00 2026-05-26T22:09:46+00:00

Drupal 6. What is the proper way to execute drupal_add_js only when specific content_type

  • 0

Drupal 6. What is the proper way to execute drupal_add_js only when specific content_type is being created?

I have some jQuery code that needs to execute only to control some form elements in a specific content_type creation.

I already have a module, which has a different name from the content_type. Is this a problem? Can I still hook onto the form? If so, what is the correct way to generate the hook to the specific node/add/content_type?

Edit: this is only needed for the creation, not the view.

Edit 2: code that’s not working at the moment:
file: testmod.module

function testmod_form_node_type_form_alter(&$form, &$form_state) {
   if ($form['#node_type']->type == 'testnode') {
     drupal_add_js(drupal_get_path('module', 'testmod') . '/new_msg.js');
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:09:46+00:00Added an answer on May 26, 2026 at 10:09 pm

    There are probably a few ways to do it but I’d use a form_alter hook:

    function mymodule_form_node_form_alter(&$form, &$form_state) {
      if (!isset($form['#node']->nid) && $form['#node']->type == 'my-type') {
        drupal_add_js('my-file.js');
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Drupal has a very well-architected, jQuery -based autocomplete.js . Usually, you don't have to
I'm a Drupal newbie plus I don't have much experience updating code, styles, and
Drupal 6.x I have this module that manages four different content types. For that
In Drupal I have the page content type. I have created a vocublary and
Using Drupal 7, using views i have created a related 'videos' block for various
Drupal has some built in views that work without Views contrib module. We even
Drupal 6. I have created a node type which consists of just a body
Drupal 6.22 I have an empty page except for a form that takes two
Drupal is very much a Do Everything CMS. There are modules that allow you
Drupal employs a custom session handler that changes the familiar...: $_SESSION['foo'] = 'bar'; echo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.