Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 22nd, 2011, 07:33 PM
Registered User
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Post Dynamically adding HTML appears not to load scripts

Hi all,

I'm quite sure there must be something obvious to this that I don't quite get. I'm writing a web app that has different pages that perform different tasks. I use ajax calls to load the "main" area while keeping the "frame" around it stable. This works very well.

I grab a whole file through a call, and get an html treein the "data" field. I add it to my framework like this:

document.getElementById("tablecell").innerHTML = pageDataFetchedFromAjax;

the html works fine, and there's no apparent jscript error. The loaded page contains a function called "fragmentInit" that I'm supposed to call to initialize the page behaviour - but apparently "fragmentInit" is undefined in the framework. The ajax callback is like this:

function onPageLoaded(oResponse)
// Should really check what we get and all that jazz.
	//if (oResponse.status == 200)
	document.getElementById("centerBlock").innerHTML = oResponse.data;
	// Now setup the page
	if (typeof fragmentInit != "undefined")	{
	alert("fragmentInit: "+(typeof fragmentInit));
Assume this function is syntactically correct - it is in the original file... - fragmentInit results in nothing, even if it's present in the loaded page.

The resulting (loaded) block appears in firefox like this:
<td id="centerBlock" colspan="1"><script type="text/javascript">

	//	Framework interface - needed on all loaded pages.
	function fragmentInit()
		var desc = makeAjaxDesc( "ajax/gameInfo.php", "datahere", onQueue, window);
Not sure what I'm doing wrong. Any clue how to fix this? I'd rather not use an iframe for a number of reasons.

EDIT: The script block in the second snippet is, in fact, correctly closed.

Last edited by calimar; February 22nd, 2011 at 07:45 PM.. Reason: fixed error
Old February 24th, 2011, 01:04 PM
Registered User
Join Date: Dec 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts


Apparently, innerHTML correctly loads the code but does not "execute" it - so the specified js functions don't work as expected.

Solved by including the code separately.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to load images dynamically on image control jazzydonald ASP.NET 2.0 Basics 10 July 13th, 2016 05:25 AM
dynamically loaded scripts chameleon Javascript 2 January 14th, 2010 08:58 AM
Dynamically load new forms into Frames MichaelS Classic ASP Professional 0 July 11th, 2006 02:59 PM
How to load the scripts into sqlserver praveenps SQL Server 2000 1 April 6th, 2006 10:55 AM
How to split pages when content load dynamically bekim Classic ASP Basics 0 August 5th, 2004 02:57 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.