To access PHP values and variables from JavaScript or convert php variables to JavaScript variables using Drupal 6, you can send them to your JavaScript code using Drupal's drupal_add_js function as follows:
drupal_to_js - Converts a PHP variable into its Javascript equivalent.
example -
$msg= 'hello dear'; //passing php variables to javascript
drupal_add_js("var apath = " . drupal_to_js($apath) . ";", 'inline');
Drupal_add_js(
'$(document).ready(function(){
alert(msg);
})',
'inline'
);
drupal_to_js - Converts a PHP variable into its Javascript equivalent.
example -
$msg= 'hello dear'; //passing php variables to javascript
drupal_add_js("var apath = " . drupal_to_js($apath) . ";", 'inline');
Drupal_add_js(
'$(document).ready(function(){
alert(msg);
})',
'inline'
);