rtarna
asked on
dynamically populate HTML table using JavaScript
I have a combo box with a list of Project names. Than I have a JavaScript array with details about those projects. The array looks like this:
aUpdates[1] = '1~82~3/15/2003~Initial stage. Project Created';
aUpdates[2] = '2~82~3/21/2003~Project has been reviewed by the Development team';
aUpdates[28] = '3~82~3/24/2003~Moved through this stage';
aUpdates[29] = '4~82~3/24/2003~Moved through this stage';
aUpdates[36] = '5~82~3/24/2003~Moved';
aUpdates[37] = '6~82~3/24/2003~Moved through this stage';
aUpdates[38] = '7~82~3/24/2003~Moved through this stage';
aUpdates[39] = '8~82~3/24/2003~Moved';
aUpdates[40] = '8~82~3/25/2003~this is a test';
This array is pre-loaded from database. Each of the array elements represent a row in a database table. If you split each of the array elements by "~" you'll get my field values. The second value, in this example it's "82", represents ID of the Project in my Combo Box.
I also have HTML table that I want to use to populate with Project information from this array. I need this table to dynamically populate when I select a value from the Combo box. If a selected combo box value does not have any details within the array, I need to hide this table. I can do this with ASP, but that means I need to reload the whole page. Is there any way to do this with JavaScript?
I don't mind changing my array as well if someone can tell me a better way of populating it to fit my purpose.
If possible, I need a piece of funcional code using the above example.
aUpdates[1] = '1~82~3/15/2003~Initial stage. Project Created';
aUpdates[2] = '2~82~3/21/2003~Project has been reviewed by the Development team';
aUpdates[28] = '3~82~3/24/2003~Moved through this stage';
aUpdates[29] = '4~82~3/24/2003~Moved through this stage';
aUpdates[36] = '5~82~3/24/2003~Moved';
aUpdates[37] = '6~82~3/24/2003~Moved through this stage';
aUpdates[38] = '7~82~3/24/2003~Moved through this stage';
aUpdates[39] = '8~82~3/24/2003~Moved';
aUpdates[40] = '8~82~3/25/2003~this is a test';
This array is pre-loaded from database. Each of the array elements represent a row in a database table. If you split each of the array elements by "~" you'll get my field values. The second value, in this example it's "82", represents ID of the Project in my Combo Box.
I also have HTML table that I want to use to populate with Project information from this array. I need this table to dynamically populate when I select a value from the Combo box. If a selected combo box value does not have any details within the array, I need to hide this table. I can do this with ASP, but that means I need to reload the whole page. Is there any way to do this with JavaScript?
I don't mind changing my array as well if someone can tell me a better way of populating it to fit my purpose.
If possible, I need a piece of funcional code using the above example.
Is there anything between:
aUpdates[2]
and
aUpdates[28]?
aUpdates[2]
and
aUpdates[28]?
ASKER
The combo is populated from an xml file with asp and below the code you'll find the xml file. And to answer your second question, no, there's nothing between aUpdates[2] and aUpdates[28]. Those are just RowIDs of the records.
========================== ========== ========== ========== =
<SELECT id=cboProjects style="FONT-SIZE: 8pt;" name=cboProjects onchange="javascript: GetProjectDetail(document. frmProject DB, cboProjects.options[cboPro jects.sele ctedIndex] .value);">
<option value="0" selected></option>
<%
Set oXML = Server.CreateObject("Micro soft.XMLDO M")
oXML.validateOnParse = True
oXML.load(Server.MapPath(" ../Files/a llProjects .xml"))
Set oRoot = oXML.documentElement
For intLoop = 0 to oRoot.childNodes.length - 1
strTemp = "<option value="
strTemp = strTemp & oRoot.childNodes.item (intLoop).getAttribute("ID ")
strTemp = strTemp & ">"
strTemp = strTemp & oRoot.childNodes(intLoop). childNodes (0).text
strTemp = strTemp & "</option>"
Response.Write strTemp
Next
Set oXML = Nothing
%>
</SELECT>
========================== ========== ========== ========== =
<?xml version='1.0'?>
<PROJECTS>
<PROJECT ID='98'>
<PROJECT_NAME>Report1</PRO JECT_NAME>
<REQUESTOR_NAME>Sandy</REQ UESTOR_NAM E>
<POPULATION>Site</POPULATI ON>
<IMPACT>Provide a one access point for monitoring.</IMPACT>
<SYSTEMS>Chronicle</SYSTEM S>
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>mst</ASSIGNED _TO>
<PROJ_START>3/10/2003</PRO J_START>
<PROJ_END>3/21/2003</PROJ_ END>
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>2</PROJECT_CA T>
</PROJECT>
<PROJECT ID='97'>
<PROJECT_NAME>Organization al Charts</PROJECT_NAME>
<REQUESTOR_NAME>Shelly</RE QUESTOR_NA ME>
<POPULATION>Site</POPULATI ON>
<IMPACT>These are provided to the dept.</IMPACT>
<SYSTEMS>TCS</SYSTEMS>
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>Rta</ASSIGNED _TO>
<PROJ_START>3/31/2003</PRO J_START>
<PROJ_END>1/1/1900</PROJ_E ND>
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>1</PROJECT_CA T>
</PROJECT>
<PROJECT ID='82'>
<PROJECT_NAME>Support Staff</PROJECT_NAME>
<REQUESTOR_NAME>Shelly</RE QUESTOR_NA ME>
<POPULATION>Site</POPULATI ON>
<IMPACT>TSC</IMPACT>
<SYSTEMS>Staffing</SYSTEMS >
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>rok</ASSIGNED _TO>
<PROJ_START>3/3/2003</PROJ _START>
<PROJ_END>3/13/2003</PROJ_ END>
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>1</PROJECT_CA T>
</PROJECT>
</PROJECTS>
==========================
<SELECT id=cboProjects style="FONT-SIZE: 8pt;" name=cboProjects onchange="javascript: GetProjectDetail(document.
<option value="0" selected></option>
<%
Set oXML = Server.CreateObject("Micro
oXML.validateOnParse = True
oXML.load(Server.MapPath("
Set oRoot = oXML.documentElement
For intLoop = 0 to oRoot.childNodes.length - 1
strTemp = "<option value="
strTemp = strTemp & oRoot.childNodes.item (intLoop).getAttribute("ID
strTemp = strTemp & ">"
strTemp = strTemp & oRoot.childNodes(intLoop).
strTemp = strTemp & "</option>"
Response.Write strTemp
Next
Set oXML = Nothing
%>
</SELECT>
==========================
<?xml version='1.0'?>
<PROJECTS>
<PROJECT ID='98'>
<PROJECT_NAME>Report1</PRO
<REQUESTOR_NAME>Sandy</REQ
<POPULATION>Site</POPULATI
<IMPACT>Provide a one access point for monitoring.</IMPACT>
<SYSTEMS>Chronicle</SYSTEM
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>mst</ASSIGNED
<PROJ_START>3/10/2003</PRO
<PROJ_END>3/21/2003</PROJ_
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>2</PROJECT_CA
</PROJECT>
<PROJECT ID='97'>
<PROJECT_NAME>Organization
<REQUESTOR_NAME>Shelly</RE
<POPULATION>Site</POPULATI
<IMPACT>These are provided to the dept.</IMPACT>
<SYSTEMS>TCS</SYSTEMS>
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>Rta</ASSIGNED
<PROJ_START>3/31/2003</PRO
<PROJ_END>1/1/1900</PROJ_E
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>1</PROJECT_CA
</PROJECT>
<PROJECT ID='82'>
<PROJECT_NAME>Support Staff</PROJECT_NAME>
<REQUESTOR_NAME>Shelly</RE
<POPULATION>Site</POPULATI
<IMPACT>TSC</IMPACT>
<SYSTEMS>Staffing</SYSTEMS
<STATUS>OPEN</STATUS>
<ASSIGNED_TO>rok</ASSIGNED
<PROJ_START>3/3/2003</PROJ
<PROJ_END>3/13/2003</PROJ_
<PRIORITYID>1</PRIORITYID>
<PROJECT_CAT>1</PROJECT_CA
</PROJECT>
</PROJECTS>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oops..
You can delete line 20:
projecttable.innerHTML = "<table>";
While your at it replace the array with this:
aUpdates = new Array();
aUpdates[1] = '1~82~3/15/2003~Initial stage. Project Created';
aUpdates[2] = '2~82~3/21/2003~Project has been reviewed by the Development team';
aUpdates[3] = '3~82~3/24/2003~Moved through this stage';
aUpdates[4] = '4~82~3/24/2003~Moved through this stage';
aUpdates[5] = '5~82~3/24/2003~Moved';
aUpdates[6] = '6~82~3/24/2003~Moved through this stage';
aUpdates[7] = '7~22~3/24/2003~Moved through this stage';
aUpdates[8] = '8~82~3/24/2003~Moved';
aUpdates[9] = '8~82~3/25/2003~this is a test';
aUpdates[10] = '8~22~3/25/2003~this is a test';
aUpdates[11] = '1~67~3/15/2003~Initial stage. Project Created';
aUpdates[12] = '2~22~3/21/2003~Project has been reviewed by the Development team';
aUpdates[13] = '3~81~3/24/2003~Moved through this stage';
aUpdates[14] = '4~81~3/24/2003~Moved through this stage';
aUpdates[15] = '5~81~3/24/2003~Moved';
aUpdates[16] = '6~81~3/24/2003~Moved through this stage';
aUpdates[17] = '7~81~3/24/2003~Moved through this stage';
aUpdates[18] = '8~81~3/24/2003~Moved';
aUpdates[19] = '8~67~3/25/2003~this is a test';
(this will give you a better understanding of what I have done) :-) good luck
Regards
You can delete line 20:
projecttable.innerHTML = "<table>";
While your at it replace the array with this:
aUpdates = new Array();
aUpdates[1] = '1~82~3/15/2003~Initial stage. Project Created';
aUpdates[2] = '2~82~3/21/2003~Project has been reviewed by the Development team';
aUpdates[3] = '3~82~3/24/2003~Moved through this stage';
aUpdates[4] = '4~82~3/24/2003~Moved through this stage';
aUpdates[5] = '5~82~3/24/2003~Moved';
aUpdates[6] = '6~82~3/24/2003~Moved through this stage';
aUpdates[7] = '7~22~3/24/2003~Moved through this stage';
aUpdates[8] = '8~82~3/24/2003~Moved';
aUpdates[9] = '8~82~3/25/2003~this is a test';
aUpdates[10] = '8~22~3/25/2003~this is a test';
aUpdates[11] = '1~67~3/15/2003~Initial stage. Project Created';
aUpdates[12] = '2~22~3/21/2003~Project has been reviewed by the Development team';
aUpdates[13] = '3~81~3/24/2003~Moved through this stage';
aUpdates[14] = '4~81~3/24/2003~Moved through this stage';
aUpdates[15] = '5~81~3/24/2003~Moved';
aUpdates[16] = '6~81~3/24/2003~Moved through this stage';
aUpdates[17] = '7~81~3/24/2003~Moved through this stage';
aUpdates[18] = '8~81~3/24/2003~Moved';
aUpdates[19] = '8~67~3/25/2003~this is a test';
(this will give you a better understanding of what I have done) :-) good luck
Regards
ASKER
Thank you. That's exactly what I needed.
I do need to use the RowIDs because they are used as links from my dynamic table.
I just had to modify the code a little to do some other things as well.
I do need to use the RowIDs because they are used as links from my dynamic table.
I just had to modify the code a little to do some other things as well.
ASKER
That's exaclty what I needed. Thanks.
No worries...
Happy programing :o)
Happy programing :o)
Can you post the code for your combo box so I can understand more what you are trying to do?