function drupal_call_js in Drupal 4
Generates a Javascript call, while importing the arguments as is. PHP arrays are turned into JS objects to preserve keys. This means the array keys must conform to JS's member naming rules.
Parameters
$function: The name of the function to call.
$arguments: An array of arguments.
Related topics
File
- includes/
common.inc, line 1272 - Common functions that many Drupal modules will need to reference.
Code
function drupal_call_js($function) {
$arguments = func_get_args();
array_shift($arguments);
$args = array();
foreach ($arguments as $arg) {
$args[] = drupal_to_js($arg);
}
$output = '<script type="text/javascript">' . $function . '(' . implode(', ', $args) . ');</script>';
return $output;
}