• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic