JavaScript,
tag & .InnerHTML Property *resolved*
ASP.NET
Thread Starter:
plenderj
Started:
Replies:
3
Ireland .NET Developer Alliance :: Forums
» Technologies » ASP.NET »
JavaScript,
tag & .InnerHTML Property *resolved*
08 Oct 2005, 1:57
plenderj
JavaScript,
tag & .InnerHTML Property *resolved*
I am really pulling my hair out at this stage and cannot figure out why my code is not working. I'm not doing anything too complicated, and this all works perfectly under Mozilla Firefox, but *will not* work under Internet Explorer.
I've expanded this out and put onto multiple lines, and also removed the other parts of js script to make it easier to read.
<
script
language
="javascript"
type
="text/javascript">
var
r;
var
p = document.getElementById(
"p"
);
function
s(e) { gr();
if
(r) { r.onreadystatechange = g;r.open(
"GET"
,
'pa.aspx?q='
+e,
true
);r.send(
""
); } }
function
g() {
if
((r.readyState == 4))
p.InnerHTML = r.responseText;
}
script
>
Now, the variable 'r' is simply either an XMLHttpRequest object or an Msxml2.XMLHTTP object depending on the browser being used. This object successfully pulls data back from my DB, but nothing will be displayed to the screen.
So
p.InnerHTML = r.responseText
doesn't actually seem to do as it's told. If I put in an
alert(p.InnerHTML)
after it, it does show me all the HTML that came back from the DB, but it's still not being displayed on the screen.
Again, this is only under IE; Firefox works perfectly.
The object p is just a
tag that's declared in HTML as follows:
<
div
id
="p"
style
="WIDTH: 600px; HEIGHT: 450px;">
div
>
This is declared above the
Jamie Plenderleith, MVP
08 Oct 2005, 5:55
paschal
Joined on 27-10-2004
Posts 108
Re: JavaScript,
tag & .InnerHTML Property
Jamie
It could be the way you reference p. IE DOM is different from the others browsers.
I suggest to use this snippet to make your code cross browser.
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
}
else if (document.all)
{
this.obj = document.all[name];
}
else if (document.layers)
{
this.obj = document.layers[name];
}
}
Then you just have to declare p as :
var p = new getObj('p');
Hope it helps
Cheers
Paschal
09 Oct 2005, 3:09
plenderj
Re: JavaScript,
tag & .InnerHTML Property
Hi Paschal,
Thanks for that. I've tried your code, and the problem has gotten a little better.
I think however it comes down to the .InnerHTML property; this one line works under Firefox and *not* under IE.
I've put your code snippet into my code, and if I test as follows:
if
(r.readyState == 4) {
var
p = getObj(
'p'
);
alert(p);
p.innerHTML = r.responseText;
}
It does popup the alertbox. Under Fx it displays [object HTMLDivElement], and under IE it displays [object]. So it's now getting the correct object reference in bother browsers, but p.innerHTML causes an unknown runtime error under IE... :(
From looking on google, there seems to be a huge number of people having problems with InnerHTML....
Jamie Plenderleith, MVP
09 Oct 2005, 4:41
plenderj
Re: JavaScript,
tag & .InnerHTML Property
Okay it's resolved. I started to build up HTML to put into the
via .innerHTML and it failed once I hit a
tag. So I removed the
from the .aspx page that was generating the content and *bing* it works!
Thanks for your help though, and for the .js you provided above :)
Jamie Plenderleith, MVP
Page 1 of 1 (4 items)
Ireland .NET Developer Alliance :: Forums
» Technologies » ASP.NET »
JavaScript,
tag & .InnerHTML Property *resolved*
(please select)
Forums Home
─» Search Forums
─» Active Topics
─» Unanswered Posts
User Options
─» Sign In
─» Create a New Account
─» Forgot Password
Meetings
─» Agenda
Technologies
─» C#
─» VB
─» ASP.NET
─» Mobile Development
─» SQL
─» Visual Studio 2005
─» .Net 2.0
─» SQL 2005
─» Web Services
─» XML
─» Windows
Architecture
─» .Net Architecture, Design and Enterprise Services
Community
─» Questions/Answers about Ireland .Net Developers Alliance
─» General Discussion