Click to See Complete Forum and Search --> : Problem with a Javascript include generated with PHP


zging
11-30-2004, 12:41 AM
Hi, I really hope some one can help me with this, as it's either REALLY WIERD, or I'm being REALLY STUPID! :D

I'm using the Tigra Scroller to show some dynamic data generated by PHP.

The Scroller uses a setup file to create some variables (collections: BEHAVE, LOOK, ITEMS is this is where the scroll data is generated) and is included in javascript dynamically using

document.write("<script src='scroll.php?i=" + n_id + "'......etc

The script is being parsed (I've thrown in a couple of alerts to check) but the variables mentioned above do not persist back into the parent doc. The error happens after the include where there is a

var thisBob = BEHAVE.auto;

which has already been set in the include (again I check the value using and alert in the include file).

In short: it seems like the include is running fine (hence the alerts) but the variables are not passed to the opening doc.

Perhaps the code will make more sense:

This is the generated code (using PHP) that is included...

alert("Test 01");

var LOOK = {
'size': [350, 100]
},

BEHAVE = {
'auto': true,
'vertical': true,
'speed': 2
},

// a data to build scroll window content
ITEMS = [
{
'file': '',
'content': 'content line 1',
'pause_b': 2,
'pause_a': 1
}
]

alert("Test 02: " + BEHAVE.auto);

This is then called in the main page using...

document.write("<script type='text/javascript' language='javascript' src='../plugins/eia_xml/scroll.php?i=" + n_id + "'><\/script><link rel='stylesheet' href='scroll" + n_id + ".css'>");


</script>

<script language="JavaScript">
function getElem(div) {
return document.getElementById ? document.getElementById(div) : document.all[div]
}

var auto = BEHAVE.auto,
vertical = BEHAVE.vertical,


I hope this explaination hasn't been to long and confusing, and thanks in advance :)

zging
11-30-2004, 01:00 AM
Sorry I forgot to include the error code! :confused:

'BEHAVE.auto' is null or not an object

zging
11-30-2004, 01:05 AM
Sorry about this, I haven't used a message board in ages :(

Here's the PHP code that generates the JS include (note the contenttype dec)

<?
header("Content-Type: text/javascript");
require("xml_serve_funcs.php");
echo apply_XML( "Scroll_data.xsl" );
?>