wheelshot
08-24-2005, 08:32 AM
Hi again,
I have 2 files. ManageDB.asp which is executed on the server ( with the <script language="javascript" runat="server">) and another one, Default.asp which is executed on the client (with the <script language="javascript">).
So here's what i would like to do. I have a function in ManageDB that fills a recordset and put it as an array and return it. In default.asp, I want to get that array from that function.
Example:
ManageDB.asp
<script language="javascript" runat="server">
function FillCrafters(the_array_name)
{
var con = Server.CreateObject("ADODB.Connection");
con.Open("Driver={Microsoft Access Driver (*.mdb)};DBQ=" + Server.MapPath("/wheelshot/Tradeskills.mdb"));
strSQLQuery = "SELECT Tradeskills.tradeskillName, Characters.* FROM Characters INNER JOIN CharTrade ON Characters.charID = CharTrade.charID INNER JOIN Tradeskills ON Tradeskills.tradeskillID = CharTrade.tradeskillID WHERE Tradeskills.tradeskillName = '" + the_array_name + "'";
var rs = Server.CreateObject("ADODB.Recordset");
rs.CursorType = 0;
rs.CursorLocation = 2;
rs.LockType = 1;
rs = con.Execute(strSQLQuery);
var craftersArray = new Array();
var loop = 0;
while (!rs.EOF)
{
craftersArray[loop] = rs.Fields.Item("charName").Value;
rs.MoveNext();
loop++;
}
rs.Close;
con.Close;
return (craftersArray);
}
</script>
Default.asp
<body background="background.jpg">
<!--#include file ="ManageDB.asp"-->
<script language="javascript">
<!--
function swapmembers(the_array_name)
{
setOptionText(document.getElementById("members"), the_array_name);
}
function setOptionText(the_select, the_array_name)
{
for (y=0; y < the_select.options.length; y++)
{
the_select.options[y] = null;
}
alert("test 1");
var craftersListTbl = FillCrafters(the_array_name);
alert(craftersListTbl.length);
var loop = 0;
for (loop=0; loop < craftersListTbl.length; loop++)
{
alert(craftersListTbl[loop]);
the_select.options[loop] = new Option(craftersListTbl[loop], craftersListTbl[loop]);
if(loop == 0)
{
the_select.options[loop].selected = true;
}
}
swaprecipes(the_select.options[0].text, the_array_name);
}
Ive checked some tutorials and no one explains how to pass variables between files like that. Tell me if you need more info.
Thanks a lot
I have 2 files. ManageDB.asp which is executed on the server ( with the <script language="javascript" runat="server">) and another one, Default.asp which is executed on the client (with the <script language="javascript">).
So here's what i would like to do. I have a function in ManageDB that fills a recordset and put it as an array and return it. In default.asp, I want to get that array from that function.
Example:
ManageDB.asp
<script language="javascript" runat="server">
function FillCrafters(the_array_name)
{
var con = Server.CreateObject("ADODB.Connection");
con.Open("Driver={Microsoft Access Driver (*.mdb)};DBQ=" + Server.MapPath("/wheelshot/Tradeskills.mdb"));
strSQLQuery = "SELECT Tradeskills.tradeskillName, Characters.* FROM Characters INNER JOIN CharTrade ON Characters.charID = CharTrade.charID INNER JOIN Tradeskills ON Tradeskills.tradeskillID = CharTrade.tradeskillID WHERE Tradeskills.tradeskillName = '" + the_array_name + "'";
var rs = Server.CreateObject("ADODB.Recordset");
rs.CursorType = 0;
rs.CursorLocation = 2;
rs.LockType = 1;
rs = con.Execute(strSQLQuery);
var craftersArray = new Array();
var loop = 0;
while (!rs.EOF)
{
craftersArray[loop] = rs.Fields.Item("charName").Value;
rs.MoveNext();
loop++;
}
rs.Close;
con.Close;
return (craftersArray);
}
</script>
Default.asp
<body background="background.jpg">
<!--#include file ="ManageDB.asp"-->
<script language="javascript">
<!--
function swapmembers(the_array_name)
{
setOptionText(document.getElementById("members"), the_array_name);
}
function setOptionText(the_select, the_array_name)
{
for (y=0; y < the_select.options.length; y++)
{
the_select.options[y] = null;
}
alert("test 1");
var craftersListTbl = FillCrafters(the_array_name);
alert(craftersListTbl.length);
var loop = 0;
for (loop=0; loop < craftersListTbl.length; loop++)
{
alert(craftersListTbl[loop]);
the_select.options[loop] = new Option(craftersListTbl[loop], craftersListTbl[loop]);
if(loop == 0)
{
the_select.options[loop].selected = true;
}
}
swaprecipes(the_select.options[0].text, the_array_name);
}
Ive checked some tutorials and no one explains how to pass variables between files like that. Tell me if you need more info.
Thanks a lot