Link to home
Start Free TrialLog in
Avatar of Malek103197
Malek103197

asked on

filling javascript 2d variable with database records?

Below is some of the code after the page is loaded. I believe the page is called Replay.asp, which is also the page the form is submitted to when the page is posted.

So, my question is - how was the 2d javascript variables filled with data from a database?..presumambly by asp code, but these variables appear to be global javascript variables..not inside a function. How was the developer able to do this..I am assuming uising asp code to acces the database.  Thanks

<SCRIPT LANGUAGE="JavaScript">

function func1() {
      ...
}
function func2() {
      ...
}

      var RP = new Array(5)
      RP[0] = new Array(62)
      RP[1] = new Array(62)
      RP[2] = new Array(62)
      RP[3] = new Array(62)
      RP[4] = new Array(62)

      RP[0][0] = 358
      RP[1][0] = 35
      RP[2][0] = '0 km/h'
      RP[3][0] = 'W'
      RP[4][0] = 'Sep 22, 2004'
      
      RP[0][1] = 358
      RP[1][1] = 35
      RP[2][1] = '0 km/h'
      RP[3][1] = 'E'
      RP[4][1] = 'Sep 22, 2004'

      ...and so on until fill up to 62

      RP[0][62] = 358
      RP[1][62] = 35
      RP[2][62] = '0 km/h'
      RP[3][62] = 'E'
      RP[4][62] = 'Sep 22, 2004'

function func3() {
      ...
}

<form name="control" action="Replay.asp" method="post">


      

      


ASKER CERTIFIED SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Malek103197
Malek103197

ASKER

Thanks for comment, but where do I insert these asp response.write statments?
Avatar of Zyloch
Or to steal a bit from Thogek, you could integrate it with your script if you felt it was easier, like this:

<script language="javascript">

RP[0][0] = <%=intVal1%>;
RP[1][0] = <%=intVal2%>;

</script>
Ok, I've got this so far...but but how do I scroll through the records from the database to fill the array?

<%
      '============open database connection & create recordset
      set oConn1=Server.CreateObject("ADODB.connection")
      oConn1.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"
      oConn1.open "C:\Inetpub\wwwroot\Reports\Fleet2000.mdb"
      set mainRS=Server.CreateObject("ADODB.recordset")
      mainRS.CursorLocation = 3 'adUseClient
      '=================================================
      sSQL3 = "Select * from MasterReports WHERE eventDate = #09/03/2004# And truckID= 'NBJ4058' ORDER BY sortDate;"
      'sSQL3 = "Select * from MasterReports WHERE truckID= 'NBJ4058' ORDER BY sortDate;"
      'sSQL3 = "Select * from MasterReports WHERE eventDate = #09/03/2004#;"
      'sSQL3 = "Select * from MasterReports;"
      mainRS.Open sSQL3, oConn1
%>
      <SCRIPT LANGUAGE="JavaScript">
      
      for (var j=0; j < 10; j++)
            for (var i=0; i < 8; i++){
                  if(i==0)
                        ReplayHistory[i][j] = 358+j;
                  else if(i==1)
                        ReplayHistory[i][j] = 35+j;
                  else
                        ReplayHistory[i][j] = '<%=mainRS("eventCode")%>';
                        
            }
            
</script>
Ah, well, if you're going to scroll through the database, it would be recommended to do it the way Thogek said--meaning you should write the whole thing out. Just move his Response.Write statement in place of ReplayHistory[i][j] = '<%=mainRS("eventCode")%>
It might help to know how the i and j variables relate to the record in the RecordSet.  I.e., should the record referenced by mainRS("eventCode") scroll with i, or j, or something else?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial