More Database Form Functions with HTML - The addRowToRecordset() Function
(Page 6 of 6 )
The addRowToRecordset() function adds a row with the information in the form Input controls to the end of the recordset. It also calls the includeInTransmittedTable('ADDED') function. This function adds the copy of the row added to the recordset to the Transmitted Table. The argument “ADDED” is the value for the last field in the row (copy) of the Transmitted Table.
Remember that if the form starts with an empty recordset, all the navigation buttons are disabled. In this case, while you are adding rows to the recordset, you enable the Show-First and Show-Previous buttons, so that you can navigate back to the rows you have added. So when the number of rows added to the recordset reaches 2, the addRowToRecordset() function enables these buttons.
To understand the details of the addRowToRecordset() function, you need to have basic knowledge in HTML DOM Table object, HTML DOM Row object, and HTML DOM Table Cell object. This is the code of the function:
function addRowToRecordset()
{
//the row is added at the end of the recordset - you can sort afterwards
//insert a blank row at the end of the table
document.getElementById('Recordset').insertRow(numberOfRows - 1);
//form the ID of the new row
rowID = 'TR' + (numberOfRows-1);
//give the new row its ID
document.getElementById('Recordset').rows[numberOfRows - 1].id = rowID;
//insert blank cells, give them IDs and their contents
for (j=0;j<6;j++)
{
//form ID for table cell
RID = "TD" + (numberOfRows - 1) + j;
//form the input text control ID
ID = "EI" + j;
document.getElementById('Recordset').rows[numberOfRows - 1].insertCell(j);
document.getElementById('Recordset').rows[numberOfRows - 1].cells[j].id = RID;
document.getElementById('Recordset').rows[numberOfRows - 1].cells[j].innerHTML = document.getElementById(ID).value;
}
//add the seventh blank cell with the value, -1, which shows that the row has not been edited
document.getElementById('Recordset').rows[numberOfRows - 1].insertCell(6);
document.getElementById('Recordset').rows[numberOfRows - 1].cells[6].innerHTML = "-1";
includeInTransmittedTable('ADDED');
//If numberOfRows is 2, enable showFirstRow and showPreviousRow Buttons since they are still disabled.
if (numberOfRows == 2)
{
enableButtons('SFA1','SP1');
index = 1; //this will be used in setting the row position number
}
}
We continue in the next part of the series.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |