Access a PHP variable in JavaScript
Also see how to add via #attached property
Set variable in PHP:
drupal_add_js(array('my_module' => array('inactive_terms' => $testvar)), array('type' => 'setting'));
You need make proper checks for variable existence as this may break all existing JavaScript execution:
Drupal.behaviors.example_behavior = {
attach: function(context, settings) {
// Check if the variable exist.
var dSettings = Drupal.settings;
if (dSettings.my_module != undefined) {
x = (dSettings.my_module.inactive_terms != undefined) ? dSettings.my_module.inactive_terms : '';
if (x != '') {
// Variable exist.
}
}
}
}