aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Strange behaviour when using getElementById() in FF 3.x Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Strange behaviour when using getElementById() in FF 3.x" Watch "Strange behaviour when using getElementById() in FF 3.x" New topic
Author

Strange behaviour when using getElementById() in FF 3.x

Robin Sharma
Ranch Hand

Joined: Aug 24, 2005
Posts: 76
Hi,
I have a query regarding the usage of document.getElementById() in FF. I was running the below code and document.getElementById() was returning a null in FF(version 3.5.7), but was working fine in IE

<input type="hidden" name="ProductName" id = "ProductName" >
<xsl:attribute name="value">
<xsl:value-of select="//Header/Terms/AdviceTrack" />
</xsl:attribute>
</input>
<input type="text" id="text1" value="abc"/>
<script language="JavaScript" type="text/javascript">

getElem(document,"ProductName");

<xsl:comment>

function getElem(doc,id) {
if (doc.getElementById) {
return doc.getElementById(id);-------> This was returning a null on FF.
} else if (doc.all) {
return doc.all[id];
} else if (doc.layers) {
return doc.layers[id];
}else{
return null; // this is not happening
}
}
</xsl:comment>
</script>

Now i removed the 'name' attribute and it seems to be working fine on both the browsers
I wanted to know the reason behind this strange behaviour of FF? and
Why was it returning a null before?


DW
There is always a bug :-)
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

I am not sure but somewhere I had heard about this problem. Try keeping name and id different,

<input type="hidden" name="ProductName" id = "ProductName2" >


Also please use CodeTags


Pawan Chopra
SCJP - DuMmIeS mInD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Showing XSL markup in an HTML forum is useless. Show the actually generated HTML, and be explicit about what id is being used.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

pawan chopra wrote:I am not sure but somewhere I had heard about this problem. Try keeping name and id different

name and id are completely different concepts. You do not need to make them differnt, though most times it makes sense to do so.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange behaviour when using getElementById() in FF 3.x