Hi!
Thanks for all your help. There were some table layout problems though when the number of columns increased. But I've worked around the problem by adding and specifying one cell at a time. Below is a short abstract of my codes:
I actually need to capture the user input in each row and calculate speed from distance and time on the same row.
(1)
Does anyone know how to retrieve the values from the function within the script? The HTML text fields are enclosed with a string variable. Where do I put the <form> </form> tags so I can get the user inputs and do the calculation within the same page?
(2)
Also, I want to save everything, (after adding rows, having user inputs in each row, and do the calculations for all rows) in a database with my SAVE button beside the ADD ROW button.
I am grateful for any help. Below are my codes:
<HTML>
<HEAD>
<script language=javascript>
var counter=0;
function addRow()
{
var tableObj=document.all.DLAtable;
var whereToInsert=tableObj.rows.length;
var newRow=tableObj.insertRow(whereToInsert-0);
var newCell=newRow.insertCell();
var cell_dateDay="<select name=sel_dateDay"+ counter++ + "><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>";
newCell.insertAdjacentHTML("AfterBegin",cell_dateDay);
var newCell=newRow.insertCell();
var cell_dateMth="<select name=sel_dateMth"+ counter++ + "><option>January</option><option>February</option><option>March</option><option>April</option><option>May</option><option>June</option><option>July</option><option>August</option><option>September</option><option>October</option><option>November</option><option>December</option>";
newCell.insertAdjacentHTML("AfterBegin",cell_dateMth);
var newCell=newRow.insertCell();
var cell_dateYr="<select name=sel_dateYr"+ counter++ + "><option>2003</option><option>2004</option><option>2005</option><option>2006</option><option>2007</option>";
newCell.insertAdjacentHTML("AfterBegin",cell_dateYr);
var newCell=newRow.insertCell();
var cell_dailydist="<INPUT type=text value='' size=5 name=txt_dailydist"+ counter++ + ">";
newCell.insertAdjacentHTML("AfterBegin",cell_dailydist);
var newCell=newRow.insertCell();
var cell_dailytimeHr="<INPUT type=text value='' size=3 name=txt_dailytimeHr"+ counter++ + ">";
newCell.insertAdjacentHTML("AfterBegin",cell_dailytimeHr);
var newCell=newRow.insertCell();
var cell_dailytimeMin="<INPUT type=text value='' size=2 name=txt_dailytimeMin"+ counter++ + ">";
newCell.insertAdjacentHTML("AfterBegin",cell_dailytimeMin);
var newCell=newRow.insertCell();
var cell_dailyspd="<INPUT type=text value='' size=4 name=txt_dailyspd"+ counter++ + "><a href='#'>[calculate]</a>";
newCell.insertAdjacentHTML("AfterBegin",cell_dailyspd);
}
</script>
</HEAD>
<BODY>
<table width="100%" bgcolor="#E8E8E8" border="1" name="DLAtable" id="DLAtable">
<tr>
<td align="center"><input type=button value="Add row" onclick="addRow()">
</td>
<!-- A save changes button to submit form values here -->
<td><input type="submit" value="Save Changes"><img src="images/save.gif">
</td>
</tr>
<tr>
<td>Date</td>
<td>Month</td>
<td>Year</td>
<td>Daily Distance</td>
<td>Daily Time (Hrs)</td>
<td>Daily Time (Mins)</td>
<td>Daily Avg Speed</td>
</tr>
</table>
</BODY>
</HTML>