How to get id when user clicks on checkbox and this check box is dynamically bind/bound. Please help me.

<div class="clearfix"></div>
<div id="test">   
<th><input type="checkbox"  id="selectall" class="chk"/></th>
  <td>Account Name</td>
  <td>Billing State</td>
   <td>phone </td>
   <td><input type="button" id="buttonClass" class="button" value="SelectAccount" /></td>

 <tbody data-bind="foreach: accountArray">


<td><input type="checkbox" data-bind="text:Id" id="myCheck" name="list"/></td>
  <td><span data-bind="text:Name" /></td>
   <td><span data-bind="text:Billingstate" /></td>
    <td><span data-bind="text:Phone" /></td>



$('#buttonClass').click(function() { debugger; 
 var x = document.getElementById("myCheck").checked; 
  var names = [];
  var i;
  $('#test input:checked').each(function(i) {

  • Where do you need the ID? In Javascript or in Apex Controller? – RajeshShah Jul 15 '16 at 7:22
  • I need this ,In javascript – user29407 Jul 15 '16 at 7:26
<input type="checkbox" data-bind="text:Id" id="myCheck" onclick="jsMethod(this);"  name="list"/>

    function jsMethod(inputtag) {
        var idProp= $(inputtag).prop('id'); // or attr() 
        var idAttr = $(inputtag).attr('id');
| improve this answer | |

You can do something like

<td><input type="checkbox" data-bind="text:Id" id="myCheck" name="list" onclick="passtheId(this);"/></td>

and then in passtheId method using this you will get all details or you can directly pass Id as well.

| improve this answer | |
  • it is not working. – user29407 Jul 15 '16 at 7:48
  • @user29407 what is not working? – Tushar Sharma Jul 15 '16 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.