Hello,
I have set theme handler for a form in Drupal and this handler has a template file. What is the easiest way to send a value from PHP to Javascript in that include file?
Thank you.
Hello,
I have set theme handler for a form in Drupal and this handler has a template file. What is the easiest way to send a value from PHP to Javascript in that include file?
Thank you.
Easiest way is just to echo it out into a script tag.
<script type="text/javascript">
var variableName = <?php echo $variable ?>;
</script>
If Drupal uses a templating language, you need to replace the <?php echo... ?>
with the relevent output method...
The standard way to do this in Drupal is with drupal_add_js, using the "setting" type, e.g.:
drupal_add_js(array('variableName' => 'value'), 'setting');
That will make the variable available on the JS side at Drupal.settings.variableName.