Can't pass php variable to javascript in Drupal 7 Can somebody help me with this problem.
In the body of a Basic page:

drupal_add_js(array('my_var' =&gt; array('orderid' =&gt; '123')), 'setting');
drupal_add_js('sites/all/scripts/printout.js');


In printout.js:

alert("Before");
alert(Drupal.settings.my_var.orderid);


Result:
"Before" was alerted then returned to Basic page, no orderid.
What have I done wrong?
Make sure you call for jquery setting inside Drupal behaviour, you can do like this:

(function ($) {
    Drupal.behaviors.example_name = {
        attach: function(context) {
            alert(Drupal.settings.my_var.orderid);
        }
    }
})(jQuery);


or you can call inside jQuery's .ready() event (less preferable than behaviours approach in Drupal world):

jQuery(document).ready(function($) {
   alert(Drupal.settings.my_var.orderid);
});


These both approaches ensure that jQuery is loaded before calling a variable.

P.S. I recommend using console.log instead of alert for quick debugging, like this:

console.log(Drupal.settings.my_var.orderid);


Then go to your developer console / firebug (depending on browser you use) and you'll see an output in console.