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.
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.
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.
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;
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.
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?
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.
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.
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
a bit of art, as a gift, that will fit in a stocking