yilmazma
07-10-2003, 03:16 AM
Hi All,
I have a question about JavaScript. I am trying to create a treeview menu with Javascript. Below, you can find some of the functions I am using :
-----------------------------------------------------
// My problem is in this function ....
function proc(nodeId, parentId, control)
{
var prock = 0;
var plevel = checkLevel(nodeId);
var slevel;
// SEE WHAT checkLevel returned :
alert(nodeId + " PLEVEL = " + plevel)
insertLine(parentId,nodeId,control,plevel);
if (control) {
for (prock=totNum-1;prock>-1;prock--)
{
if (mainElementsArray[prock][1]==nodeId && mainElementsArray[prock][0]!=nodeId)
{
tmpId_if = mainElementsArray[prock][0];
control2 = checkSubElement(tmpId_if);
slevel = checkLevel(tmpId_if);
// **********************************
// PROBLEM HERE : See that slevel is UNDEFINED
// **********************************
alert(tmpId_if + " SLEVEL = " + slevel)
proc(tmpId_if,nodeId,control2,slevel);
}
}
}
}
var glbLevelNum = 0;
function checkLevel(ID)
{
var prt = findParent(ID);
var tmpLevelNum;
if (prt != 0)
{
glbLevelNum++;
checkLevel(prt);
}
else
{
tmpLevelNum = glbLevelNum;
glbLevelNum = 0;
return tmpLevelNum;
}
}
function findParent(ID)
{
for(var fPx=0;fPx<totNum;fPx++)
{
if(mainElementsArray[fPx][0] == ID)
return mainElementsArray[fPx][1];
}
return -1;
}
----------------------------------------------------
In the function proc(...), I have a problem. The function checkLevel seems to return UNDEFINED. I could not find "why" and how to solve this problem...
Can anybody help me?
Yilmaz
I have a question about JavaScript. I am trying to create a treeview menu with Javascript. Below, you can find some of the functions I am using :
-----------------------------------------------------
// My problem is in this function ....
function proc(nodeId, parentId, control)
{
var prock = 0;
var plevel = checkLevel(nodeId);
var slevel;
// SEE WHAT checkLevel returned :
alert(nodeId + " PLEVEL = " + plevel)
insertLine(parentId,nodeId,control,plevel);
if (control) {
for (prock=totNum-1;prock>-1;prock--)
{
if (mainElementsArray[prock][1]==nodeId && mainElementsArray[prock][0]!=nodeId)
{
tmpId_if = mainElementsArray[prock][0];
control2 = checkSubElement(tmpId_if);
slevel = checkLevel(tmpId_if);
// **********************************
// PROBLEM HERE : See that slevel is UNDEFINED
// **********************************
alert(tmpId_if + " SLEVEL = " + slevel)
proc(tmpId_if,nodeId,control2,slevel);
}
}
}
}
var glbLevelNum = 0;
function checkLevel(ID)
{
var prt = findParent(ID);
var tmpLevelNum;
if (prt != 0)
{
glbLevelNum++;
checkLevel(prt);
}
else
{
tmpLevelNum = glbLevelNum;
glbLevelNum = 0;
return tmpLevelNum;
}
}
function findParent(ID)
{
for(var fPx=0;fPx<totNum;fPx++)
{
if(mainElementsArray[fPx][0] == ID)
return mainElementsArray[fPx][1];
}
return -1;
}
----------------------------------------------------
In the function proc(...), I have a problem. The function checkLevel seems to return UNDEFINED. I could not find "why" and how to solve this problem...
Can anybody help me?
Yilmaz