Click to See Complete Forum and Search --> : help with document targetting


TheSpirit
11-22-2002, 02:02 PM
This is basically a function to format (using stylesheet modifications) a table to either show or hide itself when another object calls for it. What I am interested in getting help with is the for loop and calling 2 different objects with the linkname[a] sections. It gives me an error that says, "document.all.linkname is null or is not an object."
Any ideas?

function tester(add,linkname) {
if (add=="no") { var b="2" }
else { var b="3" }
for(var a=0;a<b;a++) {
if (document.all.linkname[a].style.display=="none") { document.all.linkname[a].style.display="block" }
else { document.all.linkname[a].style.display="none" }
}
}

gil davis
11-22-2002, 03:34 PM
It should be:

document.all[linkname][a].style.display

Note the brackets around the variable "linkname".

TheSpirit
11-22-2002, 03:38 PM
okay I JUST tried blocking it... I am writing this func in an external jscript, but the page scripting won't show cause it appears to think it is a parsing error, so I will just play with it.

TheSpirit
11-22-2002, 04:33 PM
still havin trouble. Blocking the vars didn't work, as it seemed to cause a parsing error and cacel out all the javascript on the page. Hm...

gil davis
11-22-2002, 05:09 PM
I use "divide and conquer" strategy to find out what part breaks. Strategically placed alerts will indicate whether the code executes in the manner you think it should. Many times, things are so broken that no alerts are fired. You just have to keep going further towards the top of the document.

Can you post a link?

TheSpirit
11-22-2002, 05:21 PM
I'd link you, but I have done all of the testing on comp without uploading. I went through the looping already and did a document.write of all vars. They all work. The problem is that it is not parsing the linkname inside on the brackets. When I just use the coding that I showed you earlier (without any bracket usage), the page loads, but the function doesn't work. When I bracket the variable in the document.all statement, the page no longer loads, since all of the content on the page is driven by the external java script.