...

View Full Version : Adding rows dynamically



jomak73
07-19-2010, 08:50 PM
Hellooo. So I'm having trouble figuring out how to dynamically add another set of rows to a table when a button is clicked. The code below shows what goes into one set. When the button is clicked, it needs to create another three rows with the same format as the code below, but the variable names need to show what row they're on so I can easily call the values that have been inputed in another function that saves the information. Sooo for example the first variable, bhrs1-1 needs to become bhrs4-1 in the next set (because there's already a bhrs2-1 and bhrs3-1 in this set, which would become bhrs5-1 and bhrs6-1 in the new set).


Sorry the code's so long! Help would be greatly appreciated. Thanksss!!




<TBODY>
<INPUT TYPE=HIDDEN id=bhrs1-1 name=bhrs1-1><INPUT TYPE=HIDDEN id=comment1-1 name=comment1-1>
<INPUT TYPE=HIDDEN id=bhrs1-2 name=bhrs1-2><INPUT TYPE=HIDDEN id=comment1-2 name=comment1-2>
<INPUT TYPE=HIDDEN id=bhrs1-3 name=bhrs1-3><INPUT TYPE=HIDDEN id=comment1-3 name=comment1-3>
<INPUT TYPE=HIDDEN id=bhrs1-4 name=bhrs1-4><INPUT TYPE=HIDDEN id=comment1-4 name=comment1-4>
<INPUT TYPE=HIDDEN id=bhrs1-5 name=bhrs1-5><INPUT TYPE=HIDDEN id=comment1-5 name=comment1-5>
<INPUT TYPE=HIDDEN id=bhrs1-6 name=bhrs1-6><INPUT TYPE=HIDDEN id=comment1-6 name=comment1-6>
<INPUT TYPE=HIDDEN id=bhrs1-7 name=bhrs1-7><INPUT TYPE=HIDDEN id=comment1-7 name=comment1-7>
<TR>
<TD HEIGHT=20 SDVAL="1" SDNUM="1033;1033;#,##0_);[RED](#,##0)">
<SELECT style="width:500px;" name=project_id1 size=1 onChange='onProjectChanged(1);'>
<?
//
// Load Projects
//
// $sresults = mysql_query("SELECT project_id, project, billable_rate, customer_id, Customer.CustomerName FROM Project LEFT OUTER JOIN Customer ON Project.customer_id=Customer.customer_id WHERE status_id='active' ORDER BY project");

$sresults = mysql_query("SELECT project_id, project, billable_rate, Project.customer_id, CostCenter.DisplayNameShort FROM Project LEFT OUTER JOIN CostCenter ON Project.customer_id=CostCenter.customer_id WHERE status_id='active' ORDER BY customer_id,CostCenter.DisplayNameShort,project");
// $srate = 0;
print "<OPTION value='0'>--</OPTION>\n";
while($arow = mysql_fetch_assoc($sresults))
{
// $srate = $arow["billable_rate"];
print "<OPTION value=\"" . $arow["project_id"] . "\">" . substr($arow["DisplayNameShort"], 0, 15) . ": " . $arow["project"] . "</OPTION>\n";
}
// print "\n</SELECT>Billable Rate: <INPUT name=billable_rate value=\"" . $srate . "\" size=10 DISABLED></TD>\n";
?>
</TD>
<TD>
<SELECT name=task11 size=1 style="width:220px;" onChange='onTaskChange(1);'>
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-1 name=hrs1-1 size=2 maxlength=2 onFocus='onCellFocus(1,1);' onChange='calcRowTotal(1,1);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-2 name=hrs1-2 size=2 maxlength=2 onFocus='onCellFocus(1,2);' onChange='calcRowTotal(1,2);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-3 name=hrs1-3 size=2 maxlength=2 onFocus='onCellFocus(1,3);' onChange='calcRowTotal(1,3);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-4 name=hrs1-4 size=2 maxlength=2 onFocus='onCellFocus(1,4);' onChange='calcRowTotal(1,4);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-5 name=hrs1-5 size=2 maxlength=2 onFocus='onCellFocus(1,5);' onChange='calcRowTotal(1,5);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-6 name=hrs1-6 size=2 maxlength=2 onFocus='onCellFocus(1,6);' onChange='calcRowTotal(1,6);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs1-7 name=hrs1-7 size=2 maxlength=2 onFocus='onCellFocus(1,7);' onChange='calcRowTotal(1,7);'><BR>
</P>
</TD>
<TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task1total size=2 maxlength=4 DISABLED></B></FONT>
</P>
</TD>
</TR>

<INPUT TYPE=HIDDEN id=bhrs2-1 name=bhrs2-1><INPUT TYPE=HIDDEN id=comment2-1 name=comment2-1>
<INPUT TYPE=HIDDEN id=bhrs2-2 name=bhrs2-2><INPUT TYPE=HIDDEN id=comment2-2 name=comment2-2>
<INPUT TYPE=HIDDEN id=bhrs2-3 name=bhrs2-3><INPUT TYPE=HIDDEN id=comment2-3 name=comment2-3>
<INPUT TYPE=HIDDEN id=bhrs2-4 name=bhrs2-4><INPUT TYPE=HIDDEN id=comment2-4 name=comment2-4>
<INPUT TYPE=HIDDEN id=bhrs2-5 name=bhrs2-5><INPUT TYPE=HIDDEN id=comment2-5 name=comment2-5>
<INPUT TYPE=HIDDEN id=bhrs2-6 name=bhrs2-6><INPUT TYPE=HIDDEN id=comment2-6 name=comment2-6>
<INPUT TYPE=HIDDEN id=bhrs2-7 name=bhrs2-7><INPUT TYPE=HIDDEN id=comment2-7 name=comment2-7>
<TR>
<TD HEIGHT=20 SDVAL="2" SDNUM="1033;1033;#,##0_);[RED](#,##0)">
<INPUT name=remove1 value=Remove type=button onClick='removeProject(1);'>
</TD>
<TD>
<SELECT name=task12 size=1 style="width:220px;" onChange='onTaskChange(2);'>
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-1 name=hrs2-1 size=2 maxlength=2 onFocus='onCellFocus(2,1);' onChange='calcRowTotal(2,1);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-2 name=hrs2-2 size=2 maxlength=2 onFocus='onCellFocus(2,2);' onChange='calcRowTotal(2,2);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-3 name=hrs2-3 size=2 maxlength=2 onFocus='onCellFocus(2,3);' onChange='calcRowTotal(2,3);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-4 name=hrs2-4 size=2 maxlength=2 onFocus='onCellFocus(2,4);' onChange='calcRowTotal(2,4);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-5 name=hrs2-5 size=2 maxlength=2 onFocus='onCellFocus(2,5);' onChange='calcRowTotal(2,5);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-6 name=hrs2-6 size=2 maxlength=2 onFocus='onCellFocus(2,6);' onChange='calcRowTotal(2,6);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs2-7 name=hrs2-7 size=2 maxlength=2 onFocus='onCellFocus(2,7);' onChange='calcRowTotal(2,7);'><BR>
</P>
</TD>
<TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task2total size=2 maxlength=4 DISABLED></B></FONT>
</P>
</TD>
</TR>

<INPUT TYPE=HIDDEN id=bhrs3-1 name=bhrs3-1><INPUT TYPE=HIDDEN id=comment3-1 name=comment3-1>
<INPUT TYPE=HIDDEN id=bhrs3-2 name=bhrs3-2><INPUT TYPE=HIDDEN id=comment3-2 name=comment3-2>
<INPUT TYPE=HIDDEN id=bhrs3-3 name=bhrs3-3><INPUT TYPE=HIDDEN id=comment3-3 name=comment3-3>
<INPUT TYPE=HIDDEN id=bhrs3-4 name=bhrs3-4><INPUT TYPE=HIDDEN id=comment3-4 name=comment3-4>
<INPUT TYPE=HIDDEN id=bhrs3-5 name=bhrs3-5><INPUT TYPE=HIDDEN id=comment3-5 name=comment3-5>
<INPUT TYPE=HIDDEN id=bhrs3-6 name=bhrs3-6><INPUT TYPE=HIDDEN id=comment3-6 name=comment3-6>
<INPUT TYPE=HIDDEN id=bhrs3-7 name=bhrs3-7><INPUT TYPE=HIDDEN id=comment3-7 name=comment3-7>
<TR>
<TD HEIGHT=20 SDVAL="3" SDNUM="1033;1033;#,##0_);[RED](#,##0)">
<P><BR>
</P>
</TD>
<TD>
<SELECT name=task13 size=1 style="width:220px;" onChange='onTaskChange(3);'>
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-1 name=hrs3-1 size=2 maxlength=2 onFocus='onCellFocus(3,1);' onChange='calcRowTotal(3,1);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-2 name=hrs3-2 size=2 maxlength=2 onFocus='onCellFocus(3,2);' onChange='calcRowTotal(3,2);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-3 name=hrs3-3 size=2 maxlength=2 onFocus='onCellFocus(3,3);' onChange='calcRowTotal(3,3);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-4 name=hrs3-4 size=2 maxlength=2 onFocus='onCellFocus(3,4);' onChange='calcRowTotal(3,4);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-5 name=hrs3-5 size=2 maxlength=2 onFocus='onCellFocus(3,5);' onChange='calcRowTotal(3,5);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-6 name=hrs3-6 size=2 maxlength=2 onFocus='onCellFocus(3,6);' onChange='calcRowTotal(3,6);'><BR>
</P>
</TD>
<TD SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><INPUT id=hrs3-7 name=hrs3-7 size=2 maxlength=2 onFocus='onCellFocus(3,7);' onChange='calcRowTotal(3,7);'><BR>
</P>
</TD>
<TD BGCOLOR="#ffff99" SDVAL="0" SDNUM="1033;0;#,##0.0_);[RED]\(#,##0.0\)">
<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task3total size=2 maxlength=4 DISABLED></B></FONT>
</P>
</TD>
</TR>
</TBODY>

jomak73
07-19-2010, 11:24 PM
I made a button that called the following function, but it doesn't work.. which i was expecting considering i was making most of it up..



function addRow()
{
numProjects++;

//add a row to the rows collection and get a reference to the newly added row

var newRow = document.forms[0].insertRow();

//add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes

var oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-1 name=bhrs' + numProjects*3 - 2 + '-1><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-1 name=comment' + numProjects*3 - 2 + '-1>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-2 name=bhrs' + numProjects*3 - 2 + '-2><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-2 name=comment' + numProjects*3 - 2 + '-2>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-3 name=bhrs' + numProjects*3 - 2 + '-3><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-3 name=comment' + numProjects*3 - 2 + '-3>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-4 name=bhrs' + numProjects*3 - 2 + '-4><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-4 name=comment' + numProjects*3 - 2 + '-4>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-5 name=bhrs' + numProjects*3 - 2 + '-5><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-5 name=comment' + numProjects*3 - 2 + '-5>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-6 name=bhrs' + numProjects*3 - 2 + '-6><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-6 name=comment' + numProjects*3 - 2 + '-6>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-7 name=bhrs' + numProjects*3 - 2 + '-7><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-7 name=comment' + numProjects*3 - 2 + '-7>

<SELECT style="width:500px;" name=project_id' + numProjects + ' size=1 onChange="onProjectChanged(' + numProjects + ');">
<?
//
// Load Projects
//
// $sresults = mysql_query("SELECT project_id, project, billable_rate, customer_id, Customer.CustomerName FROM Project LEFT OUTER JOIN Customer ON Project.customer_id=Customer.customer_id WHERE status_id='active' ORDER BY project");

$sresults = mysql_query("SELECT project_id, project, billable_rate, Project.customer_id, CostCenter.DisplayNameShort FROM Project LEFT OUTER JOIN CostCenter ON Project.customer_id=CostCenter.customer_id WHERE status_id='active' ORDER BY customer_id,CostCenter.DisplayNameShort,project");
// $srate = 0;
print "<OPTION value='0'>--</OPTION>\n";
while($arow = mysql_fetch_assoc($sresults))
{
// $srate = $arow["billable_rate"];
print "<OPTION value=\"" . $arow["project_id"] . "\">" . substr($arow["DisplayNameShort"], 0, 15) . ": " . $arow["project"] . "</OPTION>\n";
}
// print "\n</SELECT>Billable Rate: <INPUT name=billable_rate value=\"" . $srate . "\" size=10 DISABLED></TD>\n";
?>";
');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<SELECT name=task' + numProjects + '1 size=1 style="width:220px;" onChange="onTaskChange(' + numProjects + '1);">
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>";
');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-1 name=hrs' + numProjects*3 - 2 + '-1 size=2 maxlength=2 onFocus="onCellFocus(' + numProjects*3 - 2 + ',1);" onChange="calcRowTotal(' + numProjects*3 - 2 + ',1);"><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-2 name=hrs' + numProjects*3 - 2 + '-2 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',2);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',2);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-3 name=hrs' + numProjects*3 - 2 + '-3 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',3);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',3);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-4 name=hrs' + numProjects*3 - 2 + '-4 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',4);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',4);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-5 name=hrs' + numProjects*3 - 2 + '-5 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',5);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',5);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-6 name=hrs' + numProjects*3 - 2 + '-6 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',6);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',6);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 2 + '-7 name=hrs' + numProjects*3 - 2 + '-7 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 2 + ',7);' onChange='calcRowTotal(' + numProjects*3 - 2 + ',7);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task' + numProjects + '1total size=2 maxlength=4 DISABLED></B></FONT></P>";');



var newRow = document.forms[0].insertRow();

//add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes

var oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-1 name=bhrs' + numProjects*3 - 1 + '-1><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-1 name=comment' + numProjects*3 - 1 + '-1>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-2 name=bhrs' + numProjects*3 - 1 + '-2><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-2 name=comment' + numProjects*3 - 1 + '-2>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-3 name=bhrs' + numProjects*3 - 1 + '-3><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-3 name=comment' + numProjects*3 - 1 + '-3>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-4 name=bhrs' + numProjects*3 - 1 + '-4><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-4 name=comment' + numProjects*3 - 1 + '-4>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-5 name=bhrs' + numProjects*3 - 1 + '-5><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-5 name=comment' + numProjects*3 - 1 + '-5>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-6 name=bhrs' + numProjects*3 - 1 + '-6><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-6 name=comment' + numProjects*3 - 1 + '-6>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 1 + '-7 name=bhrs' + numProjects*3 - 1 + '-7><INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 1 + '-7 name=comment' + numProjects*3 - 1 + '-7>

<INPUT name=remove' + numProjects + ' value=Remove type=button onClick="removeProject(' + numProjects + ');">
');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<SELECT name=task' + numProjects + '2 size=1 style="width:220px;" onChange="onTaskChange(' + numProjects + '2);">
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>";
');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-1 name=hrs' + numProjects*3 - 1 + '-1 size=2 maxlength=2 onFocus="onCellFocus(' + numProjects*3 - 1 + ',1);" onChange="calcRowTotal(' + numProjects*3 - 1 + ',1);"><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-2 name=hrs' + numProjects*3 - 1 + '-2 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',2);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',2);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-3 name=hrs' + numProjects*3 - 1 + '-3 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',3);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',3);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-4 name=hrs' + numProjects*3 - 1 + '-4 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',4);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',4);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-5 name=hrs' + numProjects*3 - 1 + '-5 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',5);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',5);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-6 name=hrs' + numProjects*3 - 1 + '-6 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',6);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',6);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 - 1 + '-7 name=hrs' + numProjects*3 - 1 + '-7 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 - 1 + ',7);' onChange='calcRowTotal(' + numProjects*3 - 1 + ',7);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task' + numProjects + '2total size=2 maxlength=4 DISABLED></B></FONT></P>";');




var newRow = document.forms[0].insertRow();

//add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes

var oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-1 name=bhrs' + numProjects*3 + '-1><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-1 name=comment' + numProjects*3 + '-1>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-2 name=bhrs' + numProjects*3 + '-2><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-2 name=comment' + numProjects*3 + '-2>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-3 name=bhrs' + numProjects*3 + '-3><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-3 name=comment' + numProjects*3 + '-3>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-4 name=bhrs' + numProjects*3 + '-4><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-4 name=comment' + numProjects*3 + '-4>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-5 name=bhrs' + numProjects*3 + '-5><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-5 name=comment' + numProjects*3 + '-5>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-6 name=bhrs' + numProjects*3 + '-6><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-6 name=comment' + numProjects*3 + '-6>
<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 + '-7 name=bhrs' + numProjects*3 + '-7><INPUT TYPE=HIDDEN id=comment' + numProjects*3 + '-7 name=comment' + numProjects*3 + '-7>

');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "
<SELECT name=task' + numProjects + '3 size=1 style="width:220px;" onChange="onTaskChange(' + numProjects + '3);">
<?
print "<OPTION value='0'>--</OPTION>\n";
print "<OPTION value='1'>Sales Support</OPTION>\n";
print "<OPTION value='2'>Project Management</OPTION>\n";
print "<OPTION value='3'>Discovery and Requirements Documentation</OPTION>\n";
print "<OPTION value='4'>Analysis and Design</OPTION>\n";
print "<OPTION value='5'>Coding, Unit Testing, Infrastructure Changes</OPTION>\n";
print "<OPTION value='6'>QA, Planning, System Testing</OPTION>\n";
print "<OPTION value='7'>User Acceptance Testing</OPTION>\n";
print "<OPTION value='8'>User Documentation and Training</OPTION>\n";
print "<OPTION value='9'>Launch</OPTION>\n";
print "<OPTION value='10'>Maintenance, Support, Account Management</OPTION>\n";
?>";
');
oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-1 name=hrs' + numProjects*3 + '-1 size=2 maxlength=2 onFocus="onCellFocus(' + numProjects*3 + ',1);" onChange="calcRowTotal(' + numProjects*3 + ',1);"><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-2 name=hrs' + numProjects*3 + '-2 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',2);' onChange='calcRowTotal(' + numProjects*3 + ',2);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-3 name=hrs' + numProjects*3 + '-3 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',3);' onChange='calcRowTotal(' + numProjects*3 + ',3);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-4 name=hrs' + numProjects*3 + '-4 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',4);' onChange='calcRowTotal(' + numProjects*3 + ',4);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-5 name=hrs' + numProjects*3 + '-5 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',5);' onChange='calcRowTotal(' + numProjects*3 + ',5);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-6 name=hrs' + numProjects*3 + '-6 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',6);' onChange='calcRowTotal(' + numProjects*3 + ',6);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><INPUT id=hrs' + numProjects*3 + '-7 name=hrs' + numProjects*3 + '-7 size=2 maxlength=2 onFocus='onCellFocus(' + numProjects*3 + ',7);' onChange='calcRowTotal(' + numProjects*3 + ',7);'><BR></P>";');

oCell = newRow.insertCell();
eval('oCell.innerHTML = "<P ALIGN=CENTER><FONT SIZE=3><B><INPUT id=task' + numProjects + '3total size=2 maxlength=4 DISABLED></B></FONT></P>";');
}

Old Pedant
07-20-2010, 12:00 AM
Just for starters, JavaScript does *NOT* allow you to put a single string on multiple code lines.

So


eval('oCell.innerHTML = "'
+ '<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-1 name=bhrs' + numProjects*3 - 2 + '-1>'
+ '<INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-1 name=comment' + numProjects*3 - 2 + '-1>'
+ '<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-2 name=bhrs' + numProjects*3 - 2 + '-2>'
+ ...

Didn't try to follow all the code. Fix all those strings-on-multiple-lines first, then see what you get.

Old Pedant
07-20-2010, 12:02 AM
Curious why you think you needed the eval( ) of all that stuff.

Why couldn't you just do


oCell.innerHTML =
+ '<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-1 name=bhrs' + numProjects*3 - 2 + '-1>'
+ '<INPUT TYPE=HIDDEN id=comment' + numProjects*3 - 2 + '-1 name=comment' + numProjects*3 - 2 + '-1>'
+ '<INPUT TYPE=HIDDEN id=bhrs' + numProjects*3 - 2 + '-2 name=bhrs' + numProjects*3 - 2 + '-2>'
+ ...
???

In general, eval is evil. Exceptions occur. But not that often.

jomak73
07-20-2010, 05:09 AM
i dunno. I thought you needed it if you were gonna put bits of code together. I just started javascript, php, and html like 2 weeks ago so a lot of stuff doesn't make sense



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum