Solved

filling javascript 2d variable with database records?

Posted on 2004-09-24
9
182 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now