I'm using the following line to add JavaScript code to my module form:

$form['#after_build'][] = 'myModule_after_build'

In myModule_after_build(), I add the Javascript code with calling drupal_add_js('myJavascript','inline').

Unfortunately, it seems that the JavaScript code is added only during the first page call. I would like to pass some arguments to JavaScript, and manipulate the content of the JavaScript, according to the options in the form.

Is there any configuration that I can set to add 'myJavascript' with different arguments to every button click?


#after_build is called every time the form it built. I've used this myself many times to add JS to forms. Most likely you have a flaw in the script or after build function itself, or you are using cached data when creating the script to display.

If you posted your code, we could provide a better answer.

| improve this answer | |
  • Thanks in advance. I'm using drupal_add_js to add a highcharts javascript. I'm calling this script as it is. I hope there is no flaws in it. When i've manually clear the caches using the admin menu (flush cache tables), the javascript was added. – danielmsd Aug 16 '11 at 22:58
  • @danielmsd I need to see your actual code, not a description of it – googletorp Aug 17 '11 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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