Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 14th, 2004, 02:46 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Table(s)

I have a need to build a table pulled from an array dynamically. Based on certain conditions, I need to either include or exclude items from the array in the table. I have never built a table like this. Can anyone point me in the right direction?

Clay Hess
__________________
Clay Hess
  #2 (permalink)  
Old June 14th, 2004, 03:05 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hopefully this is something like you want....

function w(txt)
{
document.write(txt);
}
w("<table>");
for(i=0;i < yourArray.length;i++)
{
if(yourArray[i].dontWrite == false)
{
w("<tr><td>");
w(yourArray[i].txtvalue);
w("</td></tr>");
}
}
w("</table>");

Adjust it and tell me if it works,

Snib

<><
  #3 (permalink)  
Old June 14th, 2004, 04:41 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Thanks for the assist...am still working on it, but I ran across something here related to this I need assistance on...How do I loop through a multidimensional array with a for loop easily? Here is a snippet of the array:

var ID = new Array();

        ID[0] = new Array();
        ID[0][0] = "3308";
        ID[0][1] = "Allow ACTIVANT to receive your alerts as an email";
        ID[0][2] = o3Web.sOptionGet(type,ID[0][0]);

        ID[1] = new Array();
        ID[1][0] = "3326";
        ID[1][1] = "Record 'An iNet Order has been placed' alerts";
        ID[1][2] = o3Web.sOptionGet(type,ID[1][0]);

        ID[2] = new Array();
        ID[2][0] = "3320";
        ID[2][1] = "Record 'QOH has gone to zero' alerts";
        ID[2][2] = o3Web.sOptionGet(type,ID[2][0]);

Is there a way to loop through a multidimensional array?

Quote:
quote:Originally posted by Snib
 Hopefully this is something like you want....

function w(txt)
{
document.write(txt);
}
w("<table>");
for(i=0;i < yourArray.length;i++)
{
if(yourArray[i].dontWrite == false)
{
w("<tr><td>");
w(yourArray[i].txtvalue);
w("</td></tr>");
}
}
w("</table>");

Adjust it and tell me if it works,

Snib

<><
Clay Hess
  #4 (permalink)  
Old June 14th, 2004, 05:06 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is what I am trying and I am getting a null or not an object error and I do not know why...

<script language="JavaScript">
var loopcounter;
for(loopcounter=0; loopcounter < ID.length; loopcounter++);
{
    document.write("<table width='386' border='2' cellpadding='2' cellspacing='0' bordercolor='#000066' bgcolor='#EBEBEB'><tr class='textsmallbold' align='left'><td width='191' valign='middle'><div align='center'>Alert</div></td><td valign='middle'><div align='center'>Current Value</div><div align='center'></div><div align='center'></div></td></tr>");
    document.write("<tr align='left'><td class='text_small' width='191' valign='middle'>");
    //Statement writes description of option. Code is repeated for each option on this page
    document.write(ID[loopcounter][1]);
    document.write("</td><td valign='middle' class='text_small'><div align='center'>");
    //Statement writes what option is currently set to. Code is repeated for each option on this page
    document.write(ID[loopcounter][2]);
    document.write("</div><div align='center'></div><div align='center'></div></td></tr>");
}
</script>



Clay Hess
  #5 (permalink)  
Old June 14th, 2004, 06:45 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

1) What line is the error on?
2) How far does the script get? Does it write anything?
3) What on earth is this?
ID[2][2] = o3Web.sOptionGet(type,ID[2][0]);

What is o3Web and sOptionGet()?

Sorry for the bombardment of questions- kind of need more info :D

Snib

Snib

<><
  #6 (permalink)  
Old June 15th, 2004, 09:08 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Bombard away! Here are my answers...

The error is on the lines that have document.write(ID[loopcounter][1]); on them. When I put the variable loopcounter in there, it errors out, but it works when I put an actual number from the array.

The script only writes the first row of the table.

Sorry for the confusion on o3Web and sOptionGet. What I am doing is writing some interface for communicating with software our developers have on a unix box. They wrote a .vbs file for me to allow that to occurr. So when I am referring to o3Web.sOptionGet, I am referring to a function in the .vbs file I have attached to my html. You can ignore that. That is working just fine.

I am doing something wrong with putting loopcounter in there, but I cannot figure out what.

Quote:
quote:Originally posted by Snib
 1) What line is the error on?
2) How far does the script get? Does it write anything?
3) What on earth is this?
ID[2][2] = o3Web.sOptionGet(type,ID[2][0]);

What is o3Web and sOptionGet()?

Sorry for the bombardment of questions- kind of need more info :D

Snib

Snib

<><
Clay Hess
  #7 (permalink)  
Old June 15th, 2004, 09:13 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Wausau, WI, USA.
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

I figured it out...all I had to do was to remove the ; from the end of my for line. Man, I hate those kind of errors. Thanks for the assist. You are always very helpful.

Clay Hess
  #8 (permalink)  
Old June 15th, 2004, 11:08 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Glad it's working :D

Let me know if you have any more problems,

Snib

<><


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Table Selection djobes31770 VB Databases Basics 7 November 19th, 2007 12:41 PM
help writing dynamic form data to dynamic table ublend SQL Server ASP 1 June 1st, 2007 08:09 AM
help writing dynamic form data to dynamic table ublend Classic ASP Professional 1 June 1st, 2007 08:08 AM
Dynamic Table phudong3da Dreamweaver (all versions) 1 April 21st, 2005 12:55 PM
Fields in a dynamic table? Roshu Javascript How-To 12 January 10th, 2005 09:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.