473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can't refer to innerHTML contents

While using innerHTML to write new HTML to a DIV element, I'm finding
that I can't refer to any new element or text within that DIV. I am
using a simple AJAX call to load a page that has some JavaScript,
which references a select box's value, and pops up an alert telling
you the ID of the option you just clicked. If I load the page
directly, if works fine, but if I load it from within another page via
AJAX, if gives me an "Object Expected" error.

Is there a better way to do this?

Thanks.

Sep 10 '07 #1
4 1216
javelin wrote:
While using innerHTML to write new HTML to a DIV element, I'm finding
that I can't refer to any new element or text within that DIV. I am
using a simple AJAX call to load a page that has some JavaScript,
which references a select box's value, and pops up an alert telling
you the ID of the option you just clicked. If I load the page
directly, if works fine, but if I load it from within another page via
AJAX, if gives me an "Object Expected" error.

Is there a better way to do this?

Thanks.
Hi,

It is not the div that somehow 'blocks references'. It is the fact your
Javascript doesn't get executed when inserted like that into a page.

Regards,
Erwin Moller
Sep 10 '07 #2
I found an odd one today.

The innerHTML thing cause some sort of wobbly in IE7.

I had a function which did lots of stuff incuding changing some text on
a screen. In IE7 it didn't work.

Eventually I discovered that nothing after a blah.innerHTML=myvariable;
command worked in that function.

So I put it at the end of the function, and all now works..

Q1/ Why?
Q2/ given a statement of the form <SPAN name="CHANGME">some text</SPAN>,
other than getelementsByName('CHANGEME')[0].InnerHTML="MYCRAP" how else
to achieve the same end?
Sep 13 '07 #3
The Natural Philosopher said the following on 9/13/2007 7:18 PM:
I found an odd one today.
An odd "what"? Please quote what you are replying to.
The innerHTML thing cause some sort of wobbly in IE7.
Test page?
I had a function which did lots of stuff incuding changing some text on
a screen. In IE7 it didn't work.
Then something else in your code was screwing it up.
Eventually I discovered that nothing after a blah.innerHTML=myvariable;
command worked in that function.
Then something else in your function was screwing it up.
So I put it at the end of the function, and all now works..
Test page?
Q1/ Why?
My stereo doesn't work. Why?
You can't diagnose what you can't see.
Q2/ given a statement of the form <SPAN name="CHANGME">some text</SPAN>,
other than getelementsByName('CHANGEME')[0].InnerHTML="MYCRAP" how else
to achieve the same end?
Parse MYCRAP and use createTextNode and createElement.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 14 '07 #4
Randy Webb wrote:
Erwin Moller said the following on 9/13/2007 5:56 AM:
>Randy Webb wrote:
>>Erwin Moller said the following on 9/12/2007 5:15 AM:
Randy Webb wrote:

<snip>

function loadHTMLFragment(elemId, HTMLFragment)

<snip>
Hi Randy,

Thanks again.
I saved that piece in my libs for future use. ;-)

Since this question (returning javascript via an xmlhttprequest)
pops up for everybody who starts with AJAX sooner or later, maybe we
should suggest to place this code into the FAQ?

That was the intent when I started working on it. The code needs some
more testing (non-PC users). I believe it is going to work anywhere
other than iCab and IE/Mac. The only thing that, I believe, needs to
be added to it for iCab and IE5.2 is a test to stay out of the
function at all since they both execute scripts inserted via
innerHTML (or that is what I have been told). I also do not know the
usage of those two browsers and whether they are even worth worrying
about.

Hi Randy,

IE5 on Mac was really a headache IMHO.
Coward as I am, I just gave up on it a few years ago after a few long
frustrating sessions.

Personally, I think IE5.2 on a mac has gone the way of NN4.xx where it
is a dead browser. It was replaced in 2003 by Safari as the default Mac
browser. No updates since 2000.
<URL: http://en.wikipedia.org/wiki/Internet_Explorer_for_Mac>
IE5.2 is still the only browser that really works on a MAC OS9 machine.

Whilst a small and dwindling population, there are still machines out
there using it.
Sep 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: necromonger | last post by:
Hi, I've got this code that creates a new new row and cell. I then put some text into the cell with innerHTML - works beautifully with Firefox but fails with IE. I guess IE doesn't support this...
4
by: bissatch | last post by:
Hi, I have the following simple HTML page. I am trying to get the innerHTML of the table element, "xmltable". I do intend to change the innerHTML of this table but at this stage I am having...
2
by: Jake Barnes | last post by:
In the function below I use a call to Prototype to get some text from another webpage and I fill a div with it. You can see the red, narrow div halfway down this page: ...
4
by: sicapitan | last post by:
I have this code snippet: updateProps snippet: if (mycheckbox.checked == '1') ? $('mycheckbox').checked = true : $('mycheckbox').checked = false; content = $('mydiv').innerHTML;
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
7
by: Lorenzo Bettini | last post by:
Hi on the same page I set the innerHTML property of an element to something like my_string + "<br />" then when I try to remove my_string + "<br />" from the innerHTML it fails since the...
5
by: pjdeklerk | last post by:
I have a web page which has javascript which uses the innerHTML property of a <TD> object to replace that table cell's contents. The contents are of the form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.