Could not convert JavaScript argument...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Could not convert JavaScript argument...

Post by bimo »

I'm getting this error:
Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: ... :: handleResponse :: line 46" data: no
and this is the line that's causing it

Code: Select all

document.getElementById('searchResults').appendChild('searchImg');
Does anyone know what this error means? Is it that I'm passing a string rather than a document object?

Any help would be much appreciated,

b
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

appendChild expects a dom object, not a string...

Code: Select all

//untested
var obj = createElement('div');
obj.innerHTML = 'text';
document.getElementById('searchResults').appendChild(obj);
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

Okay... I tried this

Code: Select all

if(http.readyState == 2 || http.readyState == 3){
		var searchImg = document.createElement('img');
		searchImg.setAttribute('src', "/design3/img/searching.gif");
		searchImg.setAttribute('id', "searching");
		document.getElementById(document.getElementById('searchResults')).appendChild('searchImg');
	}
but it didn't work and I thought about using this.something but I'm not dealing with an object.

Sorry if this is a dumb question. I have looked for the answer but there are just so many resources (books, sites) and I can't find an answer that works.

What I'm really trying to do is get it to put the loading image div into the searchResults div.

Thanks,

b.
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

tried this too:

Code: Select all

if(http.readyState == 2 || http.readyState == 3 ){
		var searchImg = document.createElement('img');
		var sRes = document.getElementById('searchResults');
		searchImg.setAttribute('src', "/design3/img/searching.gif");
		searchImg.setAttribute('id', "searching");
		sRes.innerHTML = searchImg;
		document.sRes.appendChild(searchImg);
	}
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Try:

Code: Select all

if(http.readyState == 2 || http.readyState == 3){
		searchImg = document.createElement('img');
		searchImg.setAttribute('src', "/design3/img/searching.gif");
		searchImg.setAttribute('id', "searching");
		document.getElementById('searchResults').appendChild(searchImg);
	}
In javascript, variable names must be outside of quotes to be interpreted as variables. Plus, you had some double getElementById thing going on. See if that code doesn't work.
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

Excellent, that worked. Thanks for the quote clarification.
Post Reply