Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > appendChild method not creating table properly

Reply
Thread Tools

appendChild method not creating table properly

 
 
Falc2199
Guest
Posts: n/a
 
      01-06-2004
I am using the appendChild method to create a table dynamically. The
only problem is that the code does not append the table elements to
the correct table. I basically have one table nested in another and
while I would like it append to the inner table, it appends to the
outer table.

Any help would be appereciated.

Here is the JavaScript....

function addRequest()
{
var choiceIndexValue =
parseInt(document.test1.choiceIndex.value);
var amountOfYardsValue =
parseInt(document.test1.amount_of_yards_requested. value);
var colorsValue = document.test1.color_requested.value;
var dateNeededValue = document.test1.date_needed.value;;

var tablebody = document.getElementById("toContentTBody");

var row = document.createElement("TR");
row.setAttribute("id","row"+choiceIndexValue);
row.style.background="#EBE8DF";
row.setAttribute("class","slot");
if (choiceIndexValue %2 == 0)
row.setAttribute("class","slotEven");
//row.style.background="#FAF9F6";

var cell = document.createElement("TD");
cell.setAttribute("align","center");
cell.setAttribute("valign","top");
cell.innerHTML = "<input type=checkbox id=choices name=choices>";

var cell1 = document.createElement("TD");
cell1.setAttribute("valign","top");
cell1.setAttribute("align","center");

cell1.appendChild(document.createTextNode(""+amoun tOfYardsValue));

var cell2 = document.createElement("TD");
cell2.setAttribute("valign","top");
cell2.setAttribute("align","center");

cell2.appendChild(document.createTextNode(""+color sValue));

var cell3 = document.createElement("TD");
cell3.setAttribute("valign","top");
cell3.setAttribute("align","center");
cell3.appendChild(document.createTextNode(" "+dateNeededValue));



row.appendChild(cell)//checkbox
row.appendChild(cell1);//amount
row.appendChild(cell2);//color
row.appendChild(cell3);//date needed


tablebody.appendChild(row);

}

Here is the HTML...

<TABLE backgound="" border="0" cellpadding="4" cellspacing="0"
width=100%>

<%@include file="yardage_include.jsp"%>




<TR valign="top">
<TD valign="top" align="left" nowrap colspan=4
class="slotHeader">Yardage Inquiry</TD>
</tr>
<TR>
<td colspan="4">
<table id="toContent" width="100%" cellspacing=2 cellpadding=0
border=0>
<TBODY id="toContentTBody">
<TR valign="top" class="columnHeader">
<td></td>
<TD align="left" nowrap><b>Amount In Yards</b></TD>
<TD align="left" nowrap><b>Colors </b></TD>
<TD align="left" nowrap><b>Date Needed</b></TD>
<TD align="left"></TD>
</TR>
<TR valign="top">
<td></td>

<TD nowrap align="left"><INPUT type="text"
name="amount_of_yards_requested" size="4" value="50"></TD>
<TD align=left><INPUT type="text"
name="color_requested" size="15" value="Navy"></TD>
<TD nowrap align="left"><INPUT type="text"
name="date_needed" size="10" value="5/15/2004"
align="center"></TD>
<TD align="left"><INPUT type="button" name="add_button"value="Add"
onClick="addRequest()"></TD>
</TR>
<TR >
<TD nowrap></TD>
<TD ></TD>
<TD nowrap></TD>
<TD ></TD>
</TR>
<%
if(dataVO != null ) {
Collection dataItems = dataVO.inquiryDetails;
if(dataItems == null)
dataItems = new ArrayList();
Iterator itemItr = dataItems.iterator();
while (itemItr.hasNext()) {
SampleYardageItemData itemData = (SampleYardageItemData)
itemItr.next();

%>
<TR class="slot">

<TD align="left" colspan="1" ><INPUT type="checkbox"
name="delete_select" align="center"></TD>
<TD nowrap align="left" colspan="1" ><pdd:value
text="<%=itemData.amount%>"/></TD>
<TD align="left" colspan="1" ><pdd:value
text="<%=itemData.color%>"/></TD>
<TD nowrap align="left"colspan="1" ><pdd:value
text="<%=itemData.dateNeeded %>"/></TD>
<TD></TD>
</TR>
<% } %>
</TBODY>
</table>
</td>
</TR>
<tr>
<TD valign="top" align="left" nowrap width="132">&nbsp;
Comments</TD>
<TD valign="top" align="left" colspan="3" ><TEXTAREA rows="3"
cols="35">please rush availability, buyer needs for 5/15 commit
date</TEXTAREA></TD>
</tr>
<% } %>
<TR valign="top">
<TD nowrap align="center" width="132"></TD>
<TD align="left"></TD>
<TD colspan="2" nowrap align="right" >
<INPUT type="button" name="Save" value="Save"
onclick="javascript:gotoFile('FMS/fms_search_results_details.htm')">&nbsp;
<INPUT type="button" name="Send Inquiry" value="Send Inquiry"
onclick="javascript:gotoFile('FMS/fms_search_results_details.htm')"
>&nbsp;

<INPUT type="button" name="Delete" value="Delete"
onclick="removeRequest()">&nbsp;
<INPUT type="button" name="Cancel" value="Cancel"
onclick="javascript:gotoFile('FMS/fms_search_results_details.htm')">
</TD>
</TR>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table appendChild/removeChild crashes IE6 sfeher@gmail.com Javascript 3 07-19-2006 05:15 PM
appendChild not working in IE6 Robi Javascript 3 07-24-2005 07:54 PM
appendChild checkboxes not submitting Keith Page Javascript 12 07-11-2004 04:55 PM
calculating in table made by createElement and appendChild kie Javascript 25 10-07-2003 11:38 AM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57