• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Aalok Mishra
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you actually have an id="txtSearch" on your element?

Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Paul Yule
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the generated Html for you:

 
Aparna Raghavan
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Eric
 
Aalok Mishra
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,

thanks for the tip.

 
Paul Yule
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic