0

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">   
 <table>
 <tr>
<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>
  </tr>

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

 <tr>

<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>

    </tr>
 </tbody>
 </table>

 </div>

<script>
$('#buttonClass').click(function() { debugger; 
 var x = document.getElementById("myCheck").checked; 
  var names = [];
  var i;
  $('#test input:checked').each(function(i) {
     alert(i); 
     names.push(i);
    });
     console.log(names);
 });

</script>
  • 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
0
<input type="checkbox" data-bind="text:Id" id="myCheck" onclick="jsMethod(this);"  name="list"/>

<script>
    function jsMethod(inputtag) {
        var idProp= $(inputtag).prop('id'); // or attr() 
        var idAttr = $(inputtag).attr('id');
        alert(idProp);
        alert(idAttr);
    }
</script>
| improve this answer | |
0

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.