I am working on a web site page that has me stopped over something I think should work. I am creating some parts of form dynamically, using the script below:
<script language="javascript" type="text/javascript">
for (j=0; j<numberOtherItems; j++)
{ var pitem = "otherPart" + j;
var iitem = "otherItem" + j;
var ditem = "otherPrice" + j;
var qitem = "otherQuantity" + j;
var sitem = "otherSubTotal" + j;
document.write("<tr>");
document.write("<td><input type='text' name='" + pitem + "'size='5' onfocus='blur()' /></td>");
document.write("<td><input type='text' name='" + iitem + "' size='20' onfocus='blur()' /></td>");
document.write("<td><input type='text' name='" + ditem + "' size='11' onfocus='blur()' /></td>");
document.write("<td align='center'><input type='text' name='" + qitem + "' size='5' onchange='calcAmount()' /></td>");
document.write("<td><input type='text' name='" + sitem + "' size='11' onfocus='blur()' /></td>");
document.write("</tr>");
} //end for
</script>
As you can see, this will create a set of cells five wide by the number of rows set by the variable numberOtherItems. It will also give each cell a unique identifier of the form "otherPart0" for the first cell, and so on.
What I want to do is to be able to unwind an array of values into the cells using a loop structure. I have tried code of the format below:
for (i=0; i<numberOtherItems; i++)
{
var pitem = "otherPart" + i;
var iitem = "otherItem" + i;
var ditem = "otherPrice" + i;
var qitem = "otherQuantity" + i;
var sitem = "otherSubTotal" + i;
document.OTDSupply.pitem.value=others[i].itemPartNum;
}
(The value is coming from an array of custom objects, and itemPartNum is a numerical property of that object. A simular asignment statement works fine when it is coded for each individual cell ID in a bunch of assignment statements.)
As you can see, this largly reflects the code I wrote to create the form structure, and I know that code works. However, this piece of code above doesn't work, giving me an error on the "pitem" variable in the document.OTDSupply.pitem.value=others[i].itemPartNum; line of code.
Any ideas on where I'm going wrong here??



Reply With Quote

Bookmarks