3

I'm using an Omega sub-theme and I want to do this the correct (best practice) way.

Basically I'd like to add some script so that selects a value in a select box based on a previously selected value in another select box. I have the code, just need to plug it in to my theme now.

However, I only want it to load on node creation forms of node type "X".

Any help greatly appreciated, thank you!

2 Answers 2

2

Install the JS injector module. Then go to admin/config/development/js-injector. Add a new rule. Fill the JS code field with your script.

In the Pages fieldset select the Pages on which this PHP code returns TRUE (experts only) option and enter the following code:

<?php
if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'content_type') {
 return true;
}
return false;
?>

Replace content_type with your content type name.

This is a theme independent solution. Another way is adding your script in hook_preprocess_page in template.php file of your theme.

3
  • Great, thank you. I'm using v2.0 of the js-Injector module and I have no option to select PHP input on the pages fieldset. I've put it in anyway to try it out but my directory permissions are not configured correctly, do you have any idea which permissions I need to set and where? Commented Sep 9, 2012 at 0:18
  • @jonthomas83 First enable the PHP filter module. Commented Sep 9, 2012 at 3:20
  • Thanks, PHP Filter enabled, but still no "select the Pages on which this PHP code returns TRUE", also I have an error saying "The specified file temporary://fileZXBaLq could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions." Any ideas which permissions I need to set and where? Commented Sep 10, 2012 at 13:26
1

Have you take a look to drupal native ajax?

If ahah is not good for you, you should add the jquery in the #after_build function, because when a validation go wrong, Drupal no add all the js files. With after_build function it will always add your js (http://drupal.org/node/322290#comment-1189081)

I hope this help you.

Oskar

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.