p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Dynamic Table(s) (http://p2p.wrox.com/showthread.php?t=14197)

fs22 June 14th, 2004 02:46 PM

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

Snib June 14th, 2004 03:05 PM

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

<><

fs22 June 14th, 2004 04:41 PM

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

fs22 June 14th, 2004 05:06 PM

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

Snib June 14th, 2004 06:45 PM

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

<><

fs22 June 15th, 2004 09:08 AM

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

fs22 June 15th, 2004 09:13 AM

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

Snib June 15th, 2004 11:08 AM

Glad it's working :D

Let me know if you have any more problems,

Snib

<><


All times are GMT -4. The time now is 11:20 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.