Ajith Kumar
asked on
how to merge checked column using js or jquery/
Hi, I created a table with three rows and 4 column and I have a checkbox for each row.
like this
Then if I click the merge button the row which is checked are to be merged
For example: if I selected 1st and 2nd checkbox then first two row need too merge .
like this
Then if I click the merge button the row which is checked are to be merged
<html><head>
<script>
function redclr(){
for (var i = 1; i <= 3; i++)
{
var lfckv = document.getElementById("lifecheck"+i).checked;
if (lfckv == true) {
document.getElementById("row"+i).style.backgroundColor="red";
var tds = document.getElementsByTagName("td");
var firstCellId = "";
var mergedCells = "";
for (var i = 0; i < tds.length; i++) {
mergedCells += tds[i].textContent;
if (firstCellId == "") {
firstCellId = tds[i].id;
}
else {
tds[i].style.backgroundColor = "gray";
tds[i].style.display = "none";
tds[i].textContent = "";
}
}
var firstCell = document.getElementById(firstCellId);
firstCell.textContent = mergedCells;
firstCell.style.backgroundColor = "gray";
}
}
}
</script>
<style>
table,tr,td{ border:1px solid;
width:200px;
hieght:150px;
border-collapse:collapse;
}
</style>
</head>
<body>
<table id="demo">
<tbody>
<tr id="row1">
<td id="sel1">a<input type="checkbox" id="lifecheck1"></td>
<td id="sel2">b</td>
<td id="sel3">c</td>
</tr>
<tr id="row2">
<td id="sel4">d<input type="checkbox" id="lifecheck2"></td>
<td id="sel5">e</td>
<td id="sel6">f</td>
</tr>
<tr id="row3">
<td id="sel7">g<input type="checkbox" id="lifecheck3"></td>
<td id="sel8">h</td>
<td id="sel9">i</td>
</tr>
</tbody></table>
<button type="button" onclick="redclr()">merge</button>
</body></html>
For example: if I selected 1st and 2nd checkbox then first two row need too merge .
Can you put your code here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is no activity from author.