FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Is anyone a JavaScript guru??

   
Author Topic: Is anyone a JavaScript guru??
Zeugma
Member
Member # 6636

 - posted      Profile for Zeugma   Email Zeugma         Edit/Delete Post 
I found some code online for making a neat JS menu tree, and it's working great. Unfortunately, something about it brings IEwin to its knees. Does anyone know what's wrong with this?

code:
<script language=JavaScript>

function checkBrowser(){
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
return this
}
bw=new checkBrowser()

function showhide(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
if(obj.display=='block' || obj.display=='block') obj.display='none'
else obj.display='block'
}

function show(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.display='block'
}

function hide(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.display='none'
}
</SCRIPT>

IE says the error is on the last function, something about needing an object to be declared. Then it crashes. Oi!

Thanks!

Posts: 1681 | Registered: Jun 2004  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
I know nothing about Javascript, but that is a truly horrible coding style. [Smile]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Zeugma
Member
Member # 6636

 - posted      Profile for Zeugma   Email Zeugma         Edit/Delete Post 
Yeah, and I really don't think I need all this browser check stuff, anyhow. The site isn't going to work in older browsers either way. But I don't know enough JS to know what I can safely remove from the show/hide code.... [Frown]
Posts: 1681 | Registered: Jun 2004  |  IP: Logged | Report this post to a Moderator
Zeugma
Member
Member # 6636

 - posted      Profile for Zeugma   Email Zeugma         Edit/Delete Post 
ba-da-bump?

[Smile]

Posts: 1681 | Registered: Jun 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
As stated, the coding style is really atrocious, making it hard to decipher.

If you don't need it to degrade gracefully, I think you can just modify the last function to be as follows:

code:
function hide(div,nest){
obj=document.getElementById(div).style
obj.display='none'
}

You may need to modify show similarly

code:
function show(div, nest){
obj=document.getElementById(div).style
obj.display='block'
}

and possibly showhide

code:
function showhide(div,nest){
obj=document.getElementById(div).style
if(obj.display=='block' || obj.display=='block') obj.display='none'
else obj.display='block'
}

The above code has a part that says essentially "if a or a", which seems silly, but since it shouldn't hurt anything and there may be some silly reason, I left it in.

Modify each function to what I show only if IE says its having problems with it (well, modifying them all shouldn't hurt, but its worth tracking down which one(s) IE had an issue with).

The code should work in all modern browsers.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Zeugma
Member
Member # 6636

 - posted      Profile for Zeugma   Email Zeugma         Edit/Delete Post 
Thanks a lot, fugu! That's just what I needed. [Smile]
Posts: 1681 | Registered: Jun 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
np, glad I could help.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2