• 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

document.getElementById("id").value is not supported in firefox

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have written a javascript function which runs fine in IE but when it comes down to Firefox it just craps evrything up. The function is not working at all. When I tried to find the reason I found that document.getElementById("id").value is not getting populated. Can anyone help me in it?
Here is the code:


I am sorry but I can not post entire code in here for security reasons. Please have a look at this snippet and let me know what is wrong in there.

Thanks in Advance
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you actually have an id="txtSearch" on your element?

Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

Yes I actually have id as txtSearch. Actually this is the id of the text box which the user will be using to input search string.The id is just for convience and the same code is working just fine in IE6 and above.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you used firebug [www.getFirebug.com] to add break points and see what is happening? Are you cached in Firefox with some old version? [Ctrl-R]

Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

yes I have used FireBug but of no use as such. It is saying that the object is null. The value is not getting supported and the object is displayed as null for this.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does alert(v1); say it is an object?

Can you write a dummy page with just the basics and recreate the error?

Without more info there is not much that I can do to help you.

Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

This is the message what fireBug gave to me when I tried to run that function:

document.getElementById("txtSearch") is null
displayAddResults()lookup.js (line 278)
onclick(click clientX=874, clientY=93)lookupMa...yRg%3D%3D (line 2)
[Break on this error] var v2 = document.getElementById("txtSearch").value;

The alert is displaying null
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the statement alert(document.getElementById("txtSearch")) gives you null, than that is telling me that you DO NOT have an element with an id="txtSearch" listed on the page or you are calling it before it is rendered to the page.

Reason why IE might be working is that IE says if it does not have an id of "txtSearch", it looks for a name="txtSearch", which is flat out wrong.

Eric
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would it be possible to post just the <input> tag declaration in your html. If it's created via script of some kind view the source after it's loaded and show the input tag then?
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

The id is there. I have used struts tags to define that text box. Here is the code:

 
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 Struts source in an HTML forum is useless. How is anyone supposed to know what the Struts tags generated? SHow the generated HTML.
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the generated Html for you:

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you see the html code, the name is txtSearch and not the id.. thats why it is working in IE and not in firefox... as told , if IE does not find the id it will look for name. firefox doesn't.
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that mean that I need to change all the getElementById in to getElementsByName?
But this is gonna create more trouble I guess

 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just one question Eric..
What does this mean??


Eric Pascarello Today 5:26:09 PM Subject: document.getElementById("id").value is not supported in firefox

--------------------------------------------------------------------------------

view plaincopy to clipboardprint?
document.forms[0].elementName.value = "I like cheese";
document.forms[0].elementName.value = "I like cheese";


Eric


 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is how you reference an element in a form with its name.




Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

thanks for the tip.

 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just beware that name is non-unique whereas id is. Name will get submitted with the value of your input when you post. General use is for checkboxes and radio buttons so they may share the same name with different values.

Edit: also, if I recall there is an attribute when you create the struts tag called style-id that creates the DOM id as you would with regular HTML. You maybe able to use that instead of name.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic