I have these lines of javascript code which run when the page is loaded:
(function my_function() {
//my stuff
})();
$("select#myselect").change( function() {
if ($('select#myselect').val() == '1') {
timer = setTimeout(my_function, 1000*5); //this line throws the error
} else {
if(typeof timer !== 'undefined'){
clearTimeout(timer);
}
}
});
When the line highlighted is executed it throws: "Uncaught ReferenceError: my_function is not defined"
How can I fix it?