document.getElementById

755 views
Skip to first unread message

Vanisi Stewart

unread,
Sep 1, 2010, 6:07:09 PM9/1/10
to Chromium-discuss
Does document.getElementById(loc) works in Chrome?

I am currently migrating one of the Google internal apps to work in
Chrome and I can't get any of the "document.getElementByIds" to work.
They come back as null.

Background info: It is a js file which I am using to populate a drop
down. Here is a piece of the js function I am having troubles with:

function loadMenu(loc,menu,object_type){

var xmlHttp = GetXmlHttpObject();

if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return;
}

var url="http://localhost:8080/ims/contract/feeManager/
menuGenerator.jsp?object_type=" +
object_type +
"&menu_name=" + menu +
"&menu_id=" + menu +
"&displayChoose=true" +
"&class=menuclass" +
"&onChange=addParameter('" + menu +
"');loadMenu('fee_select','fee_id','fee')";

var loading = false;
alert(url); //URL PRINTS FINE

xmlHttp.onreadystatechange=function(){

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

if(document.getElementById(loc)){ //
ERRORS OUT. COMES BACK AS NULL


alert(xmlHttp.responseText); //THE SELECT AND OPTIONS TAG PRINT FINE
JUST AS EXPECTED


document.getElementById(loc).innerHTML=xmlHttp.responseText; //ERRORS
OUT. COMES BACK AS NULL
}
//enableDisableButton();
}
}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

I've tried everything I could possibly think of. The drop down does
get displayed in Chrome. In IE it works fine.
document.getElementById(loc)
document.getElementById('loc')
document.getElementById("loc")

var theloc = loc
document.getElementById(theloc)

Nothing works. Any ideas?

Ben

unread,
Sep 1, 2010, 6:53:57 PM9/1/10
to vste...@google.com, Chromium-discuss
loc, from what I can tell, should be an element's id. It's a variable
that's set when the loadMenu function is called. If loc is a string
which doesn't coincide with any element ids on the page, then you would
get null (or undefined).

Of course, that may not be the problem, either (at least, not directly).
It might be that your xmlHttpRequest is failing (possible if you're
making a "cross-origin" request[0]). If that happens, then your
getElementById will also fail. I would check to make sure you have the
proper permissions in your manifest to perform the request (Make sure
you don't include the port--8080--in the permissions; by default, all
ports on a domain are allowed).

[0] http://code.google.com/chrome/extensions/manifest.html#permissions

--
Ben

PhistucK

unread,
Sep 2, 2010, 2:47:08 AM9/2/10
to benj...@gmail.com, vste...@google.com, Chromium-discuss
I believe he is not talking about extensions... this is chromium-discuss.

Can you show us an example of the code that calls loadMenu(...)?
And the HTML that corresponds to the element with the ID you need?

PhistucK




--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
   http://groups.google.com/a/chromium.org/group/chromium-discuss

Ben

unread,
Sep 2, 2010, 11:13:43 AM9/2/10
to PhistucK, vste...@google.com, Chromium-discuss
Ah, sorry about that; must have gotten confused.

On Thu, 2010-09-02 at 09:47 +0300, PhistucK wrote:
> I believe he is not talking about extensions... this is
> chromium-discuss.
>
>
> Can you show us an example of the code that calls loadMenu(...)?
> And the HTML that corresponds to the element with the ID you need?
>
> ☆PhistucK
>


--
Ben

Vanisi Stewart

unread,
Sep 3, 2010, 5:23:41 PM9/3/10
to Chromium-discuss
All. Thanks for the help. The solution was actually very simple.

1. The original html code was missing the attribute ID. It had only the attribute name.
2. A previous function required to get the form itself into a javascript function. I accomplished it by calling "document.getElementById('<formName>');" instead of "document.form.<field>".

Thanks,

Vanisi
Reply all
Reply to author
Forward
0 new messages