Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one TR with multiple controls in it
i.e <tr> dropdown list,textboxex ,datepickers,..</tr>
Iam adding the same row multiple time with different IDs and have some validtions(javascript)
comparisions between the rows.

How to delete selected/specific/checked row on clicking of a button?

When i delete a row my validations are not working properly which i have in for loops because
am adding IDS dynamically to my controls which are generated dynamically.
Posted
Updated 4-Feb-14 7:15am
v3
Comments
You can check if the control is selected/checked, get its parent "tr" and remove that.
Sergey Alexandrovich Kryukov 4-Feb-14 14:44pm    
By doing some programming work. What have you tried so far?
—SA

1 solution

check this out:

HTML
<html>
<head>
    <title> Add/Remove dynamic rows in HTML table </title>
    <script language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            element1.name="chkbox[]";
            cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            cell2.innerHTML = rowCount + 1;
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            element2.name = "txtbox[]";
            cell3.appendChild(element2);
 
 
        }
 
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
 
            for(var i=0; i
</script></head>
<body>
 
    <input type="button" value="Add Row" onclick="addRow('dataTable')" />
 
    <input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
 
    
        
            <input type="checkbox" name="chk" />
             1 
             <input type="text" /> 
        
    
 
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900