I've followed this : how to send variable from .php file to .js file?.
But following my code isn't working
What I want to do is whenever anybody logs in I want to send the login/password to browser javascript which will send it to another server.
It's only for a test case and not for production environment.
Details:
cyberoam.js
(function($) {
Drupal.behaviors.cyberoam = {
attach: function (context, settings) {
alert(Drupal.settings.cyberoam.login) //on commenting this below alert works
alert("hello");
}
};
})(jQuery);
In the cyberoam.module
function cyberoam_from_alter_submit(&$form, &$form_state)
{
$username = $form_state['values']['name'];
$password = $form_state['values']['pass'];
dsm($username.':'.$password); //working fine
drupal_add_js(array('cyberoam' => array('login' => $username )), 'setting');
}
What could be the problem? I've read same solution in multiple places but mine isn't working. In the Firebug console it shows TypeError: Drupal.settings.cyberoam is undefined