• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Robin Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic