Click to See Complete Forum and Search --> : Dir Tree works in IE but not NS


Goodz13
January 29th, 2003, 05:53 PM
The following JavaScript works in IE but not Netscape. Is there an easy way to get it to work in both without detecting the browser? What about another scripting language?

What it does is submits to a CGI that displays a directory Structure.


<script language="JavaScript">
<!--
var openDirNum=4;
var openDirs = new Array(4);

openDirs[0]="uploads";
openDirs[1]="uploads/test1";
openDirs[2]="uploads/test1/test1_1";
openDirs[3]="uploads/test1/test1_1/test1_1_1";

function dirOnClick(dirName) {
var i;
var bWasOpen = false;
var oDirSel;
var iIndex = 0;

for (i=0; i < openDirNum; i++) {
if (openDirs[i] == dirName) {
for (var j=i+1; j < openDirNum; j++) {
if (openDirs[j].indexOf(openDirs[i])==0)
openDirs[j] = "";
else
j = openDirNum + 1;
}
openDirs[i] = "";
bWasOpen = true;
i = openDirNum + 1;
}
}

oDirSel = document.createElement("INPUT");
oDirSel.type = "HIDDEN";
oDirSel.name ="DirSelected";

if (bWasOpen == false) {
oDirSel.value=dirName;
document.frmDirs.appendChild(oDirSel);
submitOpenDirs(dirName);
} else {
iIndex = dirName.lastIndexOf('/')
if (iIndex > 0)
oDirSel.value=dirName.substring(0, iIndex);
else
oDirSel.value="";
document.frmDirs.appendChild(oDirSel);
submitOpenDirs();
}

}
function submitOpenDirs() {
var i = 0;
var iOpen = 0;
var oFileDirs;
for (i=0; i < openDirNum; i++) {
if (openDirs[i] != "") {
iOpen++;
oFileDirs = document.createElement("INPUT");
oFileDirs.type = "HIDDEN";
oFileDirs.name ="OpenDir"+iOpen;
oFileDirs.value=openDirs[i];
document.frmDirs.appendChild(oFileDirs);
}
}
if (submitOpenDirs.arguments.length > 0) {
iOpen++;
oFileDirs = document.createElement("INPUT");
oFileDirs.type = "HIDDEN";
oFileDirs.name ="OpenDir"+iOpen;
oFileDirs.value=submitOpenDirs.arguments[0];
document.frmDirs.appendChild(oFileDirs);
}

frmDirs.submit();
}

//-->
</script>

websmith99
January 29th, 2003, 06:46 PM
Which version of Netscape are you referring to?

It will never work with Netscape 4.x because it uses W3C DOM JavaScript methods such as appendChild() for dynamically changing a node tree on the fly.

The W3C DOM is supported by Netscape 6.1+ however. Have you tested it in this?

Goodz13
January 29th, 2003, 08:18 PM
4.7 for Linux. It doesn't work with Konqueror either.

Goodz13
January 29th, 2003, 09:26 PM
Ok it somewhat works in Konqueror.

I changed the Type to text and "Alert"ed the name, the name is correct and it is displaying the correct value once I append the Input Type Text, but it isn't being submitted.

Oh and I remarked out the the code to automatically submit and added a submit button, so I could see what was going on.

I also tried using .setAttribute with the same results.

websmith99
January 29th, 2003, 10:12 PM
It should work in Mozilla, since it supports the W3C DOM

Goodz13
March 25th, 2003, 11:40 PM
Sorry I just realized that I never thanked you. Thank you very much.
I tested it on different browsers and here's my results. I guess I could have done a search to see which browsers supported W3C DOM, but I tend to do things the hard way :D

Internet Explorer 5.0 - Works!
Mozilla 1.0.1 - Doesn't Work!
Mozilla 1.0.2 - Works!
Netscape 4.x - Doesn't Work
Netscape 7.0.1 - Works!
Konqueror 3.0.3-14 - Somewhat works - Doesn't submit properly