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?
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.
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)
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.
Bookmarks