I have one problem with javascript global variable,namely,i have global variable niz_opcija2,and i initialize it in one function,but in other function,it says it is undefined..
this is my javascript:
  var niz_opcija2=[];
    window.onload=function(){
        ucitaj2();  
        ucitajKategorije();
    }
    function ucitaj2(){
        $.get("/manager/categoriesArticle",function(data){
            niz_opcija2.push(data);
            console.log(data);
            var select=document.getElementById("select3");
            for(var i=0;i<niz_opcija2[0].length;i++){
                var option=document.createElement("option");
                option.value=niz_opcija2[0][i].categoryCode;
                option.innerHTML=niz_opcija2[0][i].name;
                option.id=niz_opcija2[0][i].name;
                select.appendChild(option);
            }
        });
    }
    function ucitajKategorije(){
    for(var i=0;i<niz_opcija2[0].length;i++){
            var select=document.getElementById("selectKateg");
            var option=document.createElement("option");
            option.value=niz_opcija2[0][i].name;
            option.innerHTML=niz_opcija2[0][i].name;
            option.id=select.length;
            select.appendChild(option);
        }
    }
(in this code i am trying to get data as json using $.get,and add it to select lists select3 and selectKateg,and ucitaj2() function is getting the data,but ucitajKategorije isn't,but I think it should work the same?)Does anyone know what can be the problem?Thanks in advance!
 
    