Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object is null in IE8 and Firefox

Status
Not open for further replies.

JRye

Technical User
Nov 14, 2008
8
US
I have an expandable data tree that works in IE6 and 7, but in IE8 and Firefox, the rows will not expand. Debugging tells me that in line foldercontent.style.display="", style is a null object. Can this work in IE8 or should I used another script? Thank you for you help.

Code:
var head="display:''"
img1=new Image()
img1.src="<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/plus.gif") %>"
img2=new Image()
img2.src="<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/minus.gif") %>"

var ns6=document.getElementById&&!document.all
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1

function checkcontained(e){
var iscontained=0
cur=ns6? e.target : event.srcElement
i=0
if (cur.id=="foldheader")
iscontained=1
else
while (ns6&&cur.parentNode||(ie4&&cur.parentElement)){
if (cur.id=="foldheader"||cur.id=="foldinglist"){
iscontained=(cur.id=="foldheader")? 1 : 0
break
}
cur=ns6? cur.parentNode : cur.parentElement
}

if (iscontained){
var foldercontent=ns6? cur.nextSibling.nextSibling : cur.all.tags("UL")[0]
if (foldercontent.style.display=="none"){
foldercontent.style.display=""
cur.style.listStyleImage="url(<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/minus.gif") %>)"
}
else{
foldercontent.style.display="none"
cur.style.listStyleImage="url(<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/plus.gif") %>)"
}
}
}

if (ie4||ns6)
document.onclick=checkcontained
 
Some things to note:

- You never use the 'head' variable.

- You have lots of archaic browser sniffing code. Who uses NN6 these days? And IE4?!

Here's some much tidied code:

Code:
img1 = new Image();
img1.src = "<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/plus.gif") %>";
img2 = new Image();
img2.src = "<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/minus.gif") %>";

function checkcontained(e) {
	var cur = e ? e.target : event.srcElement;
	var iscontained = 0;
	var i = 0;

	if (cur.id == "foldheader") {
		iscontained = 1;
	} else {
		while (cur.parentNode) {
			if (cur.id == "foldheader" || cur.id == "foldinglist") {
				iscontained = (cur.id == "foldheader") ? 1 : 0;
				break;
			}
			cur = cur.parentNode;
		}
	}

	if (iscontained) {
		var foldercontent = cur.nextSibling.nextSibling;
		if (foldercontent.style.display == "none") {
			foldercontent.style.display = "";
			cur.style.listStyleImage = "url(<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/minus.gif") %>)";
		} else {
			foldercontent.style.display = "none";
			cur.style.listStyleImage = "url(<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/plus.gif") %>)";
		}
	}
}

document.onclick = checkcontained;

I have no idea if it will work or not because I know nothing of your document structure and so could not write an accurate test harness... therefore it may need some tweaking.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
IE 4 users are our largest customer base. I believe that Alexander Gram Bell originally wrote that JavaScript on an abacus. Actually it came from Dynamic Drive circa 02.

I am having the same issue in all browsers now. I am just going to use another script, but I thank you for your help.

Have a great Easter.
 
IE 4 users are our largest customer base.

[surprise] Wow - is this an intranet site? If not, what is the site? I find that so very incredibly strange!



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Some fun IE4 facts: In Feb 2005, the market share was 0.07%, is now at 0.01% and was superceded by IE5 10 years ago :)

(source: wikipedia.org)



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
I was exagerating... slightly. The company has optimized all their sites for IE 6, but I see code all the time that dates back to the late 90's. Now that IE 8 has been "released", their having all kinds of JavaScripting issues. This data tree script is for the D.U.V. on their Western Reserve Life Insurance site. The funds names are being pushed from a third party application, and since I don't see any errors when I debug the script, I think the problem might be how there bring in the data. I also inserted a script that I know works, and it had the same problem.

I thank you for your help.
Have a great Easter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top