Solved

filling javascript 2d variable with database records?

Posted on 2004-09-24
9
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

739 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