473,700 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display content of an array

Claus Mygind
571 Contributor
I have an array of objects (a hash table). My section of code, the "for in" loop (lines 18 to 41) does not execute at full speed. But if I put in an alert box (line 13) to stop program execution the the code executes when I click the Ok.

I am writing an HTML table on the fly. First I delete the content of the table, then I repopulate the table with the new content. Below the following code I display how I create the arrays (which naturally comes before this code in the actual program):

I have experimented with both using the day of the week number and the actual name of the day of the week neither way seems to work.

Attached is also a visual of the array structure.

Expand|Select|Wrap|Line Numbers
  1. function drawRTable(tbody) {
  2.     var tr, td;
  3.     tbody = document.getElementById(tbody);
  4.  
  5.     // remove existing rows, if any
  6.     while (tbody.rows.length > 0) {
  7.         tbody.deleteRow(0);
  8.     }
  9.  
  10.     var cHeaderFlag = true
  11.  
  12. //when this line is inserted the following for in loop executes
  13. alert("stop1");
  14.  
  15. /*
  16. aWeeklyTime array of object with the days of the week each day containing a variable number of entries (not important right now as I cannot get the for in loop to execute without stopping first
  17. */
  18.     for ( var i in aWeeklyTime )
  19.     {
  20.         if (cHeaderFlag)
  21.         {
  22.                     cHeaderFlag = false
  23.             tr = tbody.insertRow(tbody.rows.length);
  24.             td = tr.insertCell(tr.cells.length);
  25.             td.setAttribute("colspan", "6");
  26.             td.setAttribute("class", "subHeading4");
  27.             var cThisWeek = aWeeklyTime[i][0].weekEnd;
  28.             td.innerHTML = 'Time entered for week ending ' + cThisWeek;
  29.         }
  30.         //display day of week name
  31.         tr = tbody.insertRow(tbody.rows.length);
  32.         td = tr.insertCell(tr.cells.length);
  33.         td.setAttribute("class", "subHeading3");
  34.         td.innerHTML = aWeeklyTime[i][0].dayName;
  35.  
  36.         //fill in content
  37. //        for ( var n in aWeeklyTime[i] )
  38. //        {
  39. //        }
  40.  
  41.     }
  42.  
  43. }
  44.  

Here is how I create the array:

The arrays in this segment are as follows

aReturn is an array created with .split to parse the ajax return string (not shown here)

aDetailTime is an array also created with .split to parse each element in the aReturn array into it's subElements (line 10 below)

aTempTime is a temporary object which has one property for each element in the aDetailTime array (lines 11 thru 27 below)

aWeeklyTime array is a public array created outside the functions. Each element of aWeeklyTime is an object representing one weekday with all its detail content. (line 44 below)

Expand|Select|Wrap|Line Numbers
  1.     }else if (aReturn[0] == "~getSummary~")
  2.     {
  3.             var wkDay = "";
  4.             for (var i = 1; i < aReturn.length; i++ )
  5.             {
  6.                 //create two arrays to store the information
  7.                 var aDetailTime = new Array();
  8.                 var aTempTime = new Array();
  9.                 //parse the string into the array using the tilde to separate each value
  10.                 aDetailTime = aReturn[i].split('~');
  11.                 aTempTime[i] = new Object();
  12.                 aTempTime[i].RECKEY         = aDetailTime[0];
  13.                 aTempTime[i].EMPNO         = aDetailTime[1];
  14.                 aTempTime[i].WORKDAY     = aDetailTime[2];
  15.                 aTempTime[i].JOBID         = aDetailTime[3];
  16.                 aTempTime[i].JDEPTID     = aDetailTime[4];
  17.                 aTempTime[i].PHASECODE     = aDetailTime[5];
  18.                 aTempTime[i].PRJCTNAME     = aDetailTime[6];
  19.                 aTempTime[i].HOURS         = aDetailTime[7];
  20.                 aTempTime[i].minutes     = aDetailTime[8].substring(1) ;
  21.                 aTempTime[i].MILES         = parseInt( aDetailTime[9], 10 );
  22.                 aTempTime[i].TOLLS         = parseFloat( aDetailTime[10] );
  23.                 aTempTime[i].STARTMILES     = parseFloat( aDetailTime[11] );
  24.                 aTempTime[i].ENDMILES     = parseFloat( aDetailTime[12] );
  25.                 aTempTime[i].APPROVED     = aDetailTime[13];
  26.                 aTempTime[i].weekEnd     = aDetailTime[14];
  27.                 aTempTime[i].isDept         = aDetailTime[15];
  28.  
  29.                 var d = new Date(aTempTime[i].WORKDAY);
  30.                 chkDay = d.getDay()
  31.  
  32.                 if (wkDay != chkDay)
  33.                 {
  34.                     wkDay = chkDay;
  35.                     var cDayName = formatDate( new Date(aTempTime[i].WORKDAY), "EE" );
  36. //                    aWeeklyTime[chkDay] = new Object();
  37.                     aWeeklyTime[cDayName] = new Object();
  38.                     var cDetailCount = 0;
  39.                 }else{
  40.                     cDetailCount +=1;
  41.                 }
  42.                 aTempTime[i].dayName     = cDayName;
  43. //                aWeeklyTime[chkDay][cDetailCount] = aTempTime[i];
  44.                 aWeeklyTime[cDayName][cDetailCount] = aTempTime[i];
  45.             }
  46.  
Attached Images
File Type: gif sample array.gif (3.2 KB, 245 views)
Jan 5 '09 #1
2 4099
Claus Mygind
571 Contributor
the "for in" loop (lines 18 to 41) does not execute at full speed. But if I put in an alert box (line 13) to stop program execution the the code executes when I click the Ok.
It is all a matter of timing. 6 hours of working on this with no luck and instead it comes to me in a flash laying in bed. No matter how much you try to show the code you think is the problem, the problem always lies someplace else.

This is an ajax call to fill the hash tables (arrays). That is why it did not work at full speed, the data had not arrived.

for example (and I wish the guru's out there would have pointed this out):

In this example the browser races ahead in function A and calls C before B has returned the data (hence nothing to display, but works fine with a stop in the code like the alert box). So simply taking the call for C out of A and putting it as the last line of code in B resolves the problem

Expand|Select|Wrap|Line Numbers
  1. function A( )  //(main)
  2. {
  3.  B ( ); //(get data via Ajax
  4.  C ( ); //display data 
  5. }
  6.  
  7. function B( ) 
  8. {
  9.   Ajax call...;
  10. }
  11.  
  12. function C( )
  13. {
  14.   Display data....
  15. }
Jan 9 '09 #2
acoder
16,027 Recognized Expert Moderator MVP
Yes, this is a common problem. You could've called C() in the callback function when the readyState is 4 (complete).
Jan 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
13479
by: Brian Murphy | last post by:
I have a php-based yahoo-like web directory.I wanna give webmasters the possiblity to integrate my whole directory in their websites with their own formatting.I wanna this inclusion to be possible to all kinds of websites (ASP,PHP,... or just HTML).There are basically two files in my website: -index.php : shows the main categories along with 3 sample subcategories. -index1.php : displays the subcategories and sites of categories (exactly...
5
4986
by: christian | last post by:
Hi, i'm getting no success, with my attempt displaying some pictures one after another for i.e. some seconds. null.jpg is a white site! Really thanks for any help, regards,Christian
1
1973
by: John Fung | last post by:
Dear Everybody, I have a double menu select javascript, could anyone know how to change it, so that the result will display in a frame name called "content", please? Here is the script. <html><body> <script> <!--
4
3302
by: Hardy Wang | last post by:
Hi I have a ListBox control in my ASP.NET page. After I binding data to this control, I would like to be able to change this display order of items in this control. Just like change layout function of my.yahoo.com. I tried client side approach, yes I can change display order by JavaScript, but after clicking one of the button the display order will reverse back to its original status. Because after PostBack, the page will try to render...
1
1583
by: NH | last post by:
Hi, I'm struggling to display an image on asp.net webform (vb.net). The image is stored in a image field in a sql server database. I have read a good few solutions to it and still havnt got it working for the last 2 days. Heres my code...
9
4212
by: loudking | last post by:
Dear all, I am writing a client-server application and the client should upload a file to the server, then the server should display the content of the file in stdout. Because I have to deal with binary files, I cannot use character strings, so I chose integer array instead. But the problem is that how can I display them in stdout? I tried "%c"
15
3158
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out, of course). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Language" content="en-us" />
6
3882
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the examples I've seen are creating the information that will be displayed from scratch, while I have to use my previously created classes and add a GUI to it. I'm trying to do this GUI using JLabels but it won't let me refer to my CD class methods that...
3
2215
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i upload the script into server (Browser) it shows trimmed file names(single space for double spaces). I have checked both IE and Firefox it shows only single space file name instead on double space file name. Is it browser problem. ...
0
8647
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5903
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.