Sending variable from php to js file not working 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(&amp;$form, &amp;$form_state)
{
     $username = $form_state['values']['name'];
     $password = $form_state['values']['pass'];

     dsm($username.':'.$password); //working fine

     drupal_add_js(array('cyberoam' =&gt; array('login' =&gt; $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
You shouldn't set the values in the submit hook, you should use hook_init().

In the submit hook you should set a variable ( variable_set("name", "value") ) and read it in the hook_init using variable_get("name", "dafault_value");

On the other hand, you should NEVER add the password in js variables. It's a huge security risk.