Tabular Database Form Functions with HTML
(Page 1 of 5 )
Welcome to the ninth part of a thirteen-part series on HTML database forms. In the previous part we began our discussion of Tabular forms, having dealt with Single-Row forms up until that point. In this part we continue our discussion of what functions to use with Tabular forms and how they are different from their Single-Row counterparts.
The selectRow() Function
Before you can edit or delete, a row has to be selected. You select a row by simply clicking on it. When you do that the click event calls the selectRow() function. This function has as an argument the ID of the row clicked. With this ID the SelectRow() function changes the background color of the row to blue. Now you will see only the outline of the row because the Input Text Controls are covering much of its background.
From the row ID, the selectRow() function obtains the row position (minus 1) and makes that the index. Recall that our index variable indicates the row position that is active. This is the selectRow() function with an associated variable:
var oldRowID = ""; //when a new row is selected, use this to deselect the old row
//function to indicate that row is selected
function selectRow(ID)
{
document.getElementById(ID).style.backgroundColor = "blue";
if ((oldRowID != "")&&(oldRowID != ID))
document.getElementById(oldRowID).style.backgroundColor = "transparent";
index = parseInt(ID.charAt(2));
oldRowID = ID;
}
The effectAddEdit() function
The user clicks the conspicuous button when he has just finished typing in the ADD or EDIT mode. When he clicks the button, this function is called. The function checks to see if you were in the add mode. If you were, it adds the record to the Transmitted table. It then resets the addMode variable and makes the new row read-only, by calling the "makeReadOnlyInputControls()" function, which now takes the index as its argument.
The function also checks whether you were in the edit mode. If you were, it behaves in a manner similar to the way it did for the add mode.
The last thing the function does is enable all the buttons and then remove the conspicuous button (until it is needed again). This is the function:
function effectAddEdit()
{
//Add to transmitted table
if (addMode == true)
{
//include the added row in the transmitted table
includeInTransmittedTable('ADDED');
//after including, you must go out of the addMode, so reset the addMode variable
addMode = false;
makeReadOnlyInputControls(index);
}
//edit any row of the recordset that might have been edited at the form
if (editMode == true)
{
//include the added row in the transmitted table
includeInTransmittedTable('EDITED');
//after adding, you must go out of the editMode, so reset the editMode variable
editMode = false;
makeReadOnlyInputControls(index);
}
enableButtons('A1','E1','D1','C1','So1','S1','Do1');
//remove the button that sent the added row to the transmitted table
document.getElementById('TDAE1').style.display = "none";
}
Next: The editRow() Function >>
More HTML Articles
More By Chrysanthus Forcha