function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
krishna23krishna23 

Check box with html table

I want to display check box with records in html table 

Thanks,
Kishore
NagendraNagendra (Salesforce Developers) 
Hi Krishna,

Please find the sample code below and tweak it as per your requirement.

HTML:
<table>
    <thead>
        <tr><th></th><th>Row Text</th></tr>
    </thead>
    <tr>
        <td><input type="checkbox" /></td>
        <td>Test</td>
    </tr>
    <tr>
        <td><input type="checkbox" /></td>
        <td>Test 2</td>
    </tr>
    <tr>
        <td><input type="checkbox" /></td>
        <td>Test 3</td>
    </tr>
</table>
Javascript:
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 mark this as solved if the reply was helpful.

Thanks,
Nagendra

 
Ajay K DubediAjay K Dubedi
Hi Krishna,

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