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

Namesort iconDescription
Input validationFunctions 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;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.