PDA

View Full Version : javascript and innerHTML



rizlaa
09-08-2006, 11:38 AM
I have a region of my webpage which i am refreshing using AJAX functions.
the region contains a table of rows and a javascript function which changes the background colour of the row when hovering over it.

Initially the region will be empty and then rows displayed as a user enters parameters by replacing the empty div using AJAX and innerHTML. I have found that the row highlighting fails with 'object not found' if i insert the row highlighting function via innerHTML along with the retrieved rows. If i include the function in the empty div in the original page source however everything is fine.

I also found that as long as the function is in the original page source replacing with the same function via AJAX and innerHTML does not cause it to fail.

Is there any way of getting the page to be able to use javascript functions added via innerHTML??

hope the above makes sense and any help is much appreciated...

ItsMeOnly
09-08-2006, 03:03 PM
AFAIR basically the div gets properties of an "object" element when you use AJAX to fill its contents, so you need to treat it like it was a new document window (or iframe) with javascript.

Twey
09-08-2006, 09:06 PM
You need to run through the scripts in the element and execute them all.
for(var i = 0, e = element.getElementsByTagName("script"); i < e.length; ++i)
eval(e[i].innerHTML);This won't work with external scripts.