drupal_call_js
Definition
drupal_call_js($function)
includes/common.inc, line 1272
Description
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
| Name | Description |
|---|---|
| Input validation | Functions to validate user input. |
Code
<?php
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;
}
?> 