checkboxes = document.getElementsByTagName("input");
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
checkbox.onclick = function() {
var currentRow = this.parentNode.parentNode;
var secondColumn = currentRow.getElementsByTagName("td")[1];
alert("My text is: " + secondColumn.textContent );
};
}
For more information please refer to below link which might help you further.
Please find the sample code below and tweak it as per your requirement.
HTML: Javascript: For more information please refer to below link which might help you further.
- https://stackoverflow.com/questions/40085969/displaying-rows-in-a-table-first-with-checked-checkbox
Please mark this as solved if the reply was helpful.Thanks,
Nagendra
Try this code:
<apex:page >
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<html>
<body>
<h2>Basic HTML Table</h2>
<br/>
<table style="width:100%">
<tr>
<th> <input type="checkbox" onclick="selectAllCheckboxes(this,'inputId')"/> </th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td><input type="checkbox" Id="inputId"/> </td>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td><input type="checkbox" Id="inputId"/> </td>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td><input type="checkbox" Id="inputId" /> </td>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
</apex:page>
Hope this code will help you. Please mark it as Best Answer if you find it helpful.
Thanks.
Ajay Dubedi