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


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">



Who is Participating?
ThogekConnect With a Mentor Commented:
We'd have to see the server-side ASP code to answer for certain, but there's no reason that ASP code could not access a database, gather certain values, and then write out the JavaScript code in the page containing those values -- just like it might for any HTML part of the page.

For example:

    Response.write "RP[0][0] = " & intVal1
    Response.write "RP[1][0] = " & intVal2
    Response.write "RP[2][0] = '" & intKPH & " km/h'"

Malek103197Author Commented:
Thanks for comment, but where do I insert these asp response.write statments?
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%>;

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Malek103197Author Commented:
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" "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++){
                        ReplayHistory[i][j] = 358+j;
                  else if(i==1)
                        ReplayHistory[i][j] = 35+j;
                        ReplayHistory[i][j] = '<%=mainRS("eventCode")%>';
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?
ZylochConnect With a Mentor Commented:
Yes, a possible workaround would be something like this:


You can loop that 5 times for RP[0][0] to RP[4][0] then redo it again and again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.