www.webdeveloper.com
Results 1 to 4 of 4

Thread: Lose connection to javascripts with ajax

  1. #1
    Join Date
    Apr 2007
    Posts
    4

    Lose connection to javascripts with ajax

    I have, for example, scriptaculous.js in my <head> tags. If I use innerhtml with ajax to replace the content of a div, the scriptaculous functions that i have in that innerhtml will no longer work. Do I need to reinitiate the javascripts with innerhtml or something?

    thanks in advance

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    Any JavaScript that exists between SCRIPT tags does not get parsed into memory when using innerHTML. Also, if you have added JavaScript event handlers to any HTML tags using JavaScript, you'll need to redo it each time the innerHTML is changed. I found it easiest to create event handlers inline, like onclick="foo();". I think there is a function in Scriptaculous that executes javascript in innerHTML text. Can't remember what it is though. It might be an option you set when creating a new instance of the Ajax object.

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    thanks for your reply! Is there anyway that I can replace the contents of a div and keep the reference to these javascripts. I have a calendar script that, when a button is clicked, pops up a calendar to select a date. When the user clicks edit on the flight, i lightbox a div with innerhtml being a form with that flights information. The user can change the date of the flight. (Just to give you a little context)

  4. #4
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,755
    Nope. The innerHTML property always skips over JavaScript. That's just the way it works.

    After the innerHTML is updated, you can then execute another script that updates the DOM to attach any missing event handlers, or include those event handlers inline as I mentioned above. And as I mentioned above, you can eval the JavaScripts with a special function in Prototype, the library that Scriptaculous is based on.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles