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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript works in IE but not in FF 1

Status
Not open for further replies.

bhuninghake

Programmer
Mar 24, 2004
90
US
This page ( was originally written in asp gathering the information on each state from sql, but I've redone it so the source code could be viewed. THe following is the java script i'm using and the div tags. Everything works perfectly in IE, but I'm unable to figure out the problem why it won't work in FireFox.

Code:
<script Language="JavaScript">
<!--
var head = "display:''"
function doit( header )
{
  var head = header.style
  if (head.display=="none")
    head.display=""
  else
    head.display="none"
}
//-->
</script>


<div id="container"><div id="content">
<br />
<h3 onClick="doit(document.all[this.sourceIndex+1])" title="Click here to expand/contract!" style="cursor: hand;">Connecticut</h3>
<p class="borderbottom" style="font-weight: bold; display: none; head;">
	&nbsp;&nbsp;&nbsp; Information about the state <br />
	&nbsp;&nbsp;&nbsp; Information about the capital</p>
</div></div>

Any help on what I'm missing would be deeply appreciated...
 
[!]document.all[/!] is not supported by firefox.

You should give the paragraph tag an id, and then use getElementById to grab a reference to that tag to pass to the function:

Code:
<h3 onClick="doit([!]document.getElementById('whatever')[/!])" title="Click here to expand/contract!" style="cursor: hand;">Connecticut</h3>
<p class="borderbottom" [!]id="whatever"[/!] style="font-weight: bold; display: none; head;">
    &nbsp;&nbsp;&nbsp; Information about the state <br />
    &nbsp;&nbsp;&nbsp; Information about the capital</p>

-kaht

 
Thanks kaht ... your suggestion worked perfectly. Overlooked the obvious, "document.all is not supported by firefox".

 
Hi

kaht said:
document.all is not supported by firefox.
Generally, yes. Because generally we talk about standard compliant documents.

However, the document mentioned by bhuninghake is rendered in quirks mode, so sadly there is [tt]document.all[/tt] available.

The unavailable thing is the [tt]sourceIndex[/tt] property of the elements. If you add them "manually", that code should work :
JavaScript:
window.onload=function() {
  if (document.body.sourceIndex==undefined) {
    var e=document.getElementsByTagName('*');
    for (var i=0,l=e.length;i<l;i++) e[i].sourceIndex=i
  }
}
Please consider this only information. The solution is the one posted by kaht.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top