Solved

filling javascript 2d variable with database records?

Posted on 2004-09-24
9
189 Views
Last Modified: 2006-11-17
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">


      

      


0
Comment
Question by:Malek103197
  • 3
  • 2
  • 2
9 Comments
 
LVL 15

Accepted Solution

by:
Thogek earned 125 total points
ID: 12144815
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'"

etc.
0
 

Author Comment

by:Malek103197
ID: 12149101
Thanks for comment, but where do I insert these asp response.write statments?
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12149181
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>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Malek103197
ID: 12149239
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>
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12151012
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")%>
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12151625
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?
0
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 125 total points
ID: 12151726
Yes, a possible workaround would be something like this:

RP[RP.length][RP[0].length]=something

You can loop that 5 times for RP[0][0] to RP[4][0] then redo it again and again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question