By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Remove row & change id's

P: 2
I want to remove one row from table by clicking on remove link(one for each row) and change their id's correspondingly(like remove 2nd row and assign 3rd row id=2nd row id i.e.,shift row id's)
Oct 20 '08 #1
Share this Question
Share on Google+
3 Replies


RamananKalirajan
100+
P: 607
Hello Sir,
U can delete the particular row with the row index which is autogenerated in the Table, why do u want to change the rowId. I dont get ur point.

[HTML]<html>
<head>
<script type="text/javascript">
function doThis()
{
var myTab = document.getElementById('myTable');
var row=myTab.rows.length;
var y=myTab.insertRow(row);

var a=y.insertCell(0);
var xx= document.createElement('input');
xx.type="text";
a.appendChild(xx);

var b=y.insertCell(1);
var xx= document.createElement('input');
xx.type="text";
b.appendChild(xx);

var c=y.insertCell(2);
var xx= document.createElement('input');
xx.type="button";
xx.value="Remove"
xx.onclick="removeThis(this)"
c.appendChild(xx);
c.innerHTML = c.innerHTML;
}

function removeThis(ths)
{
var rIndex = ths.parentNode.parentNode.rowIndex;
alert("rIndex = "+rIndex);
document.getElementById('myTable').deleteRow(rInde x);

}
</script>

</head>
<body>
<br/>
<input type="button" value="Add" onclick="doThis()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>Name</th>
<th>Wage</th>
<th></th>
</tr>
</table>
</body>
</html>[/HTML]

Regards
Ramanan Kalirajan
Oct 20 '08 #2

P: 2
Thanks for kind reply.

Actually in my code i have Browse....Button(i.e. <input type='file'>) and remove(<a href=''>). By clicking on remove link it has to remove current row and like that it has to proceed. I want to check whether every row(every type='file' value) is null('') or some file is selected to upload a file. For that reason it has to remove current selected row and here with row id's problem comes in checking. Plz if u have any idea or code plz forward me..

Thanks again for ur kind reply




Hello Sir,
U can delete the particular row with the row index which is autogenerated in the Table, why do u want to change the rowId. I dont get ur point.

[HTML]<html>
<head>
<script type="text/javascript">
function doThis()
{
var myTab = document.getElementById('myTable');
var row=myTab.rows.length;
var y=myTab.insertRow(row);

var a=y.insertCell(0);
var xx= document.createElement('input');
xx.type="text";
a.appendChild(xx);

var b=y.insertCell(1);
var xx= document.createElement('input');
xx.type="text";
b.appendChild(xx);

var c=y.insertCell(2);
var xx= document.createElement('input');
xx.type="button";
xx.value="Remove"
xx.onclick="removeThis(this)"
c.appendChild(xx);
c.innerHTML = c.innerHTML;
}

function removeThis(ths)
{
var rIndex = ths.parentNode.parentNode.rowIndex;
alert("rIndex = "+rIndex);
document.getElementById('myTable').deleteRow(rInde x);

}
</script>

</head>
<body>
<br/>
<input type="button" value="Add" onclick="doThis()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
<tr>
<th>Name</th>
<th>Wage</th>
<th></th>
</tr>
</table>
</body>
</html>[/HTML]

Regards
Ramanan Kalirajan
Oct 20 '08 #3

RamananKalirajan
100+
P: 607
Thanks for kind reply.

Actually in my code i have Browse....Button(i.e. <input type='file'>) and remove(<a href=''>). By clicking on remove link it has to remove current row and like that it has to proceed. I want to check whether every row(every type='file' value) is null('') or some file is selected to upload a file. For that reason it has to remove current selected row and here with row id's problem comes in checking. Plz if u have any idea or code plz forward me..

Thanks again for ur kind reply

This could help u out, but i dont know wether its ur requirement. Its just a small idea

[HTML]<html>
<head>
<script type="text/javascript">
function doThis()
{
var myTab = document.getElementById('myTable');
var xx= document.createElement('input');
xx.type="file";

var row=myTab.rows.length;
var y=myTab.insertRow(row) ;
var b=y.insertCell(0);
b.appendChild(xx);
b.innerHTML = b.innerHTML;

var xy=document.createElement('input');
xy.type="button";
xy.value="Remove";
xy.onclick="removeThis(this)";
var c=y.insertCell(1);
c.appendChild(xy);
c.innerHTML=c.innerHTML;
}
function removeThis(ths)
{
var rowIndex = ths.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(rowIn dex);
}
</script>
</head>
<body>
<input type="button" value="Attachment" onclick="doThis()">
<br/>
<table id="myTable" border="1" cellspacing="5" cellpadding="5">
</table>
</body>
</html>[/HTML]

Regards
Ramanan Kalirajan
Oct 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.