Results 1 to 3 of 3

Thread: javascript and innerHTML

  1. #1
    Join Date
    Mar 2006
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript and innerHTML

    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...

  2. #2
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need to run through the scripts in the element and execute them all.
    Code:
    for(var i = 0, e = element.getElementsByTagName("script"); i < e.length; ++i)
      eval(e[i].innerHTML);
    This won't work with external scripts.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •