I got 2 jQUERY functions - and i want to pass a variable from the first to the second. From what i read i need to set the variable as a global variable, but the methods i read and try to reproduce doesn't seem to work.

you add custom attribute to '#slider-range' in the first function, and in the second you can get one
–
Anton BaksheievSep 22 '12 at 21:52

you declare var param;(technicaly it will be the same window.param) if you call the second function firstly this param will be 'underfind'. but if you call the first function and after that second you will be able get this param.
–
Anton BaksheievSep 22 '12 at 21:57

Well, I usually prefer the use of Namespaces, it's more elegant, and you can reference to the variable anywhere on the page.

The setup I normally use is like this:

var Namespace = (function() {
return {
/**
* Initialize the page.
*/
init: function() {
//Here you can set Global Variables
//inside the Namespace using "this"
this.variable1 = true;
this.variable2 = false;
//You may call other functions
this.setListeners();
},
setListeners() {
//You may reference the variables using "this"
if(this.variable1 == true) {
alert(this.variable2);
}
},
otherFunction() {
//When calling functions with callbacks,
//you should set a variable inside the function
//so you may use that in the callbacks to the namespace
var self = this;
$("#target").click(function() {
//Now you can use the variable self in the callbacks
alert(self.variable1);
//Or you may also use the namespace
alert(Namespace.variable1);
});
}
};
})();
$(document).ready(function(){
//Here you may call the init function which should fire
//everything else you need in the page load
Namespace.init();
});
//You may also use the variables anywhere else in the page
//or in other Javascript files by referencing to the namespace
//Variable
Namespace.variable1;
Namespace.variable2;
//Function
Namespace.otherFunction();

This structure makes the code cleaner and easy to reference by other scripts.

Hi Nicolini. Yes, i can see that it would make sense to build it otherwise, and i might want to change the structure also because i want the initization to come from either(more) variables changing. Thanks for the contribution!
–
NielsSep 23 '12 at 1:16