Hi,
I am using replace method in my javascript function with regular expression. The following is the function.
<script language="javascript">
var rowNum = 1;
function addRow()
{
tabBody = document.getElementById('insert').firstChild;
newRow = tabBody.appendChild(tabBody.firstChild.cloneNode(true));
rowNum = rowNum + 1;
for(i=0;i<newRow.cells.length;i++)
{
newRow.cells.innerHTML = newRow.cells.innerHTML.replace(/1([^\d])/g, rowNum+'$1');
}
}
</script>
The above function creates a new row in the table and increments the column name by 1. However, in the above function, if I pass a variable in place of 1, this does not work. Can anyone help me how to do this.
var temp=1;
{
newRow.cells.innerHTML = newRow.cells.innerHTML.replace(/temp([^\d])/g, rowNum+'$1');
}
My purpose is that I have some 4 rows in a upper table above this and want this table to start a new row with column name as 5. So I am passing the no. of rows in the above in a variable to this function. However, the replace function is not taking it.
Thanks,
Krishna
I am using replace method in my javascript function with regular expression. The following is the function.
<script language="javascript">
var rowNum = 1;
function addRow()
{
tabBody = document.getElementById('insert').firstChild;
newRow = tabBody.appendChild(tabBody.firstChild.cloneNode(true));
rowNum = rowNum + 1;
for(i=0;i<newRow.cells.length;i++)
{
newRow.cells.innerHTML = newRow.cells.innerHTML.replace(/1([^\d])/g, rowNum+'$1');
}
}
</script>
The above function creates a new row in the table and increments the column name by 1. However, in the above function, if I pass a variable in place of 1, this does not work. Can anyone help me how to do this.
var temp=1;
{
newRow.cells.innerHTML = newRow.cells.innerHTML.replace(/temp([^\d])/g, rowNum+'$1');
}
My purpose is that I have some 4 rows in a upper table above this and want this table to start a new row with column name as 5. So I am passing the no. of rows in the above in a variable to this function. However, the replace function is not taking it.
Thanks,
Krishna