6

I was trying to call drupal_add_js in the callback of a button. It seems, even with after_build, that this can be done successfully only you are working without cached data.

So, before i start the page, i run drupal_flush_all_caches, and the javascript is successfully added to the page.

The problem is I want to get some user input data from a form, pass to the javascript and exibit the result. The way i'm trying to do, it is getting a string that contains the processed values and concatenating with another string that contains the other part of the javascript (probably this is not a good practice), and calling this string with drupal_add_js. But, when if i call drupal_flush_all_caches, the form will be reset and i will not be able to get the data.

So, my questions are: How can i pass values from a form to a javascript?

Do i need to flush all caches every time to use drupal_add_js?

Is there different solutions to deal with this during development and production?


Thanks for the help guys. I found some answers: How can i pass values from a form to a javascript? I had to name my variable as Drupal.settings.myModule.myVar in the javascript code. This way i can pass variables from php code to javascript. If you want to modify the javascript code you really need to flush caches. Until now, i have not found nothing about differences between production and development best pratices.

1
  • Do you pass only data from the user function to the javascript which is added to the page, or also javascript code? Commented Aug 19, 2011 at 17:16

2 Answers 2

1

Is there any problem with writing a menu callback that does this, and processing in PHP?

If you must use JavaScript for the processing, why not intercept the user's value in JavaScript and never "really" submit the form?

0
1

I think you can add the javascript using Drupal.behaviors. This will ensure that the javascript code gets reloaded even if the page is cached.

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.