> -----Original Message----- > From: Brad Wood [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 07, 2007 6:55 PM > To: CF-Talk > Subject: Dynamic JS > > If I am returning HTML via an Ajax call to stick in my page, JavaScript > functions aren't available for me to call, and other inline JavaScript > doesn't get executed.
My PanelManager component has a solution for part of this. It's not officially released yet (I'm not done with the documentation), but it's available here: http://www.depressedpress.com/Content/Development/JavaScript/Extensions/DP_P anelManager/Index.cfm The thing that might help is the Panel.Load() method. Panel.load = function(Content) { // "null" the old (to clear it) Panel.innerHTML = null; // Load the content Panel.innerHTML = Content; // Load Scripts var AllScripts = Panel.getElementsByTagName("script"); var AllScriptsCnt = AllScripts.length; for (var Cnt = 0; Cnt < AllScriptsCnt; Cnt++){ var CurScript = document.createElement('script'); CurScript.type = "text/javascript"; CurScript.text = AllScripts[Cnt].text; Panel.appendChild(CurScript); }; }; This method loads content into a panel (really just any HTML element). The trick is the "Load Scripts" block - it searches the new content for <script> blocks and adds any it finds dynamically to the document. Once this is done any script in those blocks will be available - I've tested this in IE, FireFox and Opera 9 (actually... come to think of it I'm pretty such I tested it in Opera... I tested everything else using it). You can use this function almost as is generically. Changing the first line to something like this should work: loadContent = function(Panel, Content) { You can then pass "Panel" into the function (a reference to an HTML element like a DIV as retrieved from document.getElementById(ID). But the PanelManager as a component is pretty slick (I think) - it adds basic animation and management techniques to HTML elements allowing you to move, fade, position them easily. It also gives you methods for determining window and canvas size and getting the mouse position. Anyway... enough plugging. ;^) For complex applications I use a modification of this that assists with script corruption issues (issues that might occur when script from many sources is thrown together). I create scopes (similar to CF scopes) in JavaScript - for example "Page" and "App" and so forth. These are just objects: var Page = new Object; When I load a page I load all script into that object. For example: Page.PageVar = X; Page.myFunction = function() { }; When a new page is loaded you just null out and recreate the "Page" giving you a nice clean blank slate. Jim Davis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:269118 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

