J
JonH
Ok, I have this dynamically created table in my one of my php forms
that shows the names of the people the user has entered into a text
field. When they hit add a row displays, showing the name they entered.
Also, an image that allows them to delete shows beside the name upon
creation. The delete removes the name from the table and pushes the
other names to the top. Simple stuff, however, if I delete the last
name displayed(the bottom of the table), then the next, then the next,
IN ORDER, I have no problems. If I pick a name that is in the middle or
top of the table, everything below does not allow me to delete
For instance
Enter name (Text field)
BUTTON
X 1
X 2
X 3
If I clicked the x on 3,then 2, then 1...no problems, if i click 2,
then 1, then i cannot delete 3
if I click 1, then i cannot delete 2, or 3
I hope that explains it, Here is my function that does it it feeds off
another function to delete the rows, and I have tried
tbl.DeleteRows(RowIndex) and I have tried lastRow(My tbl length var) by
its self and -1
Please help
function addGranteeNameToDisplay()
{
var oCell;
var oRow;
var tbl = document.getElementById( 'granteeNameDisplayTable' );
var lastRow = tbl.rows.length;
var iteration = lastRow-1;
//Update the 'hidden' value grantorNames so that when the user
//checks out we will have it
var name = document.getElementById('granteeLastName').value;
if (name != "" || document.getElementById('granteeFirstName').value
!= '')
{
//if there is a first name, add it with a comma
if( document.getElementById('granteeFirstName').value != '' )
name = name + ', ' +
document.getElementById('granteeFirstName').value;
//add name to hidden value on form
document.getElementById('granteeNames').value = name+'|';
oRow = tbl.insertRow(lastRow);
oCell = oRow.insertCell(0);
var imgAnchor = document.createElement( 'a' );
imgAnchor.onclick = function(){
var names = new Array();
names = document.getElementById('granteeNames').value.split(',');
names.splice( index, 1 );
document.getElementById('granteeNames').value =
names.join('|');
//tbl.deleteRow(lastRow);
removeRowFromTable( 'granteeNameDisplayTable',lastRow);
document.getElementById('granteeLastName').value = '';
document.getElementById('granteeFirstName').value = '';
return;
//addGranteeNameToDisplay();
}
imgAnchor.onmouseover = function(){ return escape( 'Click here to
delete' ) };
imgAnchor.setAttribute( 'href', 'javascript:void(0)' );
var imageNode = document.createElement( 'img' );
imageNode.setAttribute( 'border', 0 );
imageNode.setAttribute( 'src', pathToImages+'delete.gif' );
imageNode.setAttribute( 'width', 15 );
imageNode.setAttribute( 'height', 15 );
imgAnchor.appendChild( imageNode );
oCell.appendChild( imgAnchor );
var oCell2 = oRow.insertCell(1);
var textNode = document.createTextNode(lastRow);
if( name )
textNode.data = name;
oCell2.appendChild( textNode );
document.getElementById('granteeLastName').value = '';
document.getElementById('granteeFirstName').value = '';
}
}
function removeRowFromTable( tableID, index )
{
var tbl = document.getElementById(tableID);
var lastRow = tbl.rows.length;
// add one because index is zero based and number of rows is 1 based
tbl.deleteRow( index );
return;
}
that shows the names of the people the user has entered into a text
field. When they hit add a row displays, showing the name they entered.
Also, an image that allows them to delete shows beside the name upon
creation. The delete removes the name from the table and pushes the
other names to the top. Simple stuff, however, if I delete the last
name displayed(the bottom of the table), then the next, then the next,
IN ORDER, I have no problems. If I pick a name that is in the middle or
top of the table, everything below does not allow me to delete
For instance
Enter name (Text field)
BUTTON
X 1
X 2
X 3
If I clicked the x on 3,then 2, then 1...no problems, if i click 2,
then 1, then i cannot delete 3
if I click 1, then i cannot delete 2, or 3
I hope that explains it, Here is my function that does it it feeds off
another function to delete the rows, and I have tried
tbl.DeleteRows(RowIndex) and I have tried lastRow(My tbl length var) by
its self and -1
Please help
function addGranteeNameToDisplay()
{
var oCell;
var oRow;
var tbl = document.getElementById( 'granteeNameDisplayTable' );
var lastRow = tbl.rows.length;
var iteration = lastRow-1;
//Update the 'hidden' value grantorNames so that when the user
//checks out we will have it
var name = document.getElementById('granteeLastName').value;
if (name != "" || document.getElementById('granteeFirstName').value
!= '')
{
//if there is a first name, add it with a comma
if( document.getElementById('granteeFirstName').value != '' )
name = name + ', ' +
document.getElementById('granteeFirstName').value;
//add name to hidden value on form
document.getElementById('granteeNames').value = name+'|';
oRow = tbl.insertRow(lastRow);
oCell = oRow.insertCell(0);
var imgAnchor = document.createElement( 'a' );
imgAnchor.onclick = function(){
var names = new Array();
names = document.getElementById('granteeNames').value.split(',');
names.splice( index, 1 );
document.getElementById('granteeNames').value =
names.join('|');
//tbl.deleteRow(lastRow);
removeRowFromTable( 'granteeNameDisplayTable',lastRow);
document.getElementById('granteeLastName').value = '';
document.getElementById('granteeFirstName').value = '';
return;
//addGranteeNameToDisplay();
}
imgAnchor.onmouseover = function(){ return escape( 'Click here to
delete' ) };
imgAnchor.setAttribute( 'href', 'javascript:void(0)' );
var imageNode = document.createElement( 'img' );
imageNode.setAttribute( 'border', 0 );
imageNode.setAttribute( 'src', pathToImages+'delete.gif' );
imageNode.setAttribute( 'width', 15 );
imageNode.setAttribute( 'height', 15 );
imgAnchor.appendChild( imageNode );
oCell.appendChild( imgAnchor );
var oCell2 = oRow.insertCell(1);
var textNode = document.createTextNode(lastRow);
if( name )
textNode.data = name;
oCell2.appendChild( textNode );
document.getElementById('granteeLastName').value = '';
document.getElementById('granteeFirstName').value = '';
}
}
function removeRowFromTable( tableID, index )
{
var tbl = document.getElementById(tableID);
var lastRow = tbl.rows.length;
// add one because index is zero based and number of rows is 1 based
tbl.deleteRow( index );
return;
}