PDA

View Full Version : external js file stores data


glevine
08-24-2005, 08:13 PM
I am currently trying to write a page to display data that is stored in external js files. On the first page, a user enters

an id number and that is sent to a new page using a query string. the id # is then concatenated with 2 other pieces of data

to form a string which represents the src of the external js file. I then need to grab data from a 4 dimensional array that

resides in the js file, in the form:


var rawStats=[
["0001","Y","Name Name","2005","R"],
["0001","Y","Name Name","2005","R"],
["0001","Y","Name Name","2005","R"],
[]
];

rawBatting.length=rawBatting.length-1; //to make up for that last empty row


I only need to access the name at this point, but I'm really not sure how to do that. All of my google searches and random

trials haven't turned up anything yet. Thanks in advance for any help you can give me.

Here is the page I currently have written to display data:

<html>
<head>
<title>Batter</title>
</head>
<body>
<p><script language="JavaScript"><!--
function GetParam(param)
{
var start=location.search.indexOf("?"+param+"=");
if (start<0) start=location.search.indexOf("&"+param+"=");
if (start<0) return ' ';
start += param.length+2;
var end=location.search.indexOf("&",start)-1;
if (end<0) end=location.search.length;
var result=location.search.substring(start,end);
var result=' ';
for(var i=start;i<=end;i++)
{
var c=location.search.charAt(i);
result=result+(c=='+'?' ':c);
}
return unescape(result);
}

var jsfile=' ';
var jsfilesrc=' ';

if (location.search!='')
{
document.write('This page was opened with the following data:<br>');
document.write('Param id = ');
document.write(GetParam('id'));
jsfile='p'+GetParam('id')+'Bat.js';
document.write('<br>JS File = '+jsfile);
jsfilesrc='url/to/location/of/js/files'+jsfile;
document.write('<br>jsfilesrc = '+jsfilesrc);
}
// --></script></p>
<p>
<script language="JavaScript" src=jsfilesrc><!--
//HERE'S WHERE I BELIEVE A FUNCTION NEEDS TO GO TO ACCESS DATA
// --></script>
</p>
</body>
</html>

glevine
08-24-2005, 08:43 PM
To clarify my actual need:

I have Page A which takes user input in the form of an id #. Page B takes that input in the form of a query string and constructs a filename, e.g user enters the number 3, and the script in Page A will make a filename of "somescript_3.js". It will then request that script, and access a variable inside of it. The part I need help with is actually accessing/using the variable inside of the external script. I attempted to output rawBatting.length as an easy way to test that I could get something out of the script, but I ended up with no data being written to the page and IE said my page was written with errors. Of course the error it said existed was line 2 col 1, which is the beginning bracket of the html tag. So basically I need some assistance in taking the data from any variable in my ext js file and putting it on my webpage. Thanks.

nikkiH
08-24-2005, 08:58 PM
I make dynamic script elements in one of my scripts here.
You can do something similar, but just dynamically construct the src attribute.
http://www.ipwebdesign.net/useful_dynamicSelectsDB.html