Home > DeveloperSection > Forums > How to get the id of the checkbox that has just been checked by the user using jQuery?
Ankit Singh

Total Post:341

Points:2389
Posted on    August-25-2014 1:11 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 580  View(s)
Rate this:

How to get the id of the checkbox that has just been checked by the user using jQuery?

<div data-role="fieldcontain" style="margin: 0px">

    <fieldset data-role="controlgroup">

        <asp:Repeater ID="rpt" runat="server">

            <ItemTemplate>

                <input type="checkbox" name="chkBox"

                    id="<%# DataBinder.Eval(Container.DataItem, "[MemberId]").ToString() %>"

                    class="custom" /><label for="<%# DataBinder.Eval(Container.DataItem, "[MemberId]").ToString() %>"><%# DataBinder.Eval(Container.DataItem, "[LastName]").ToString() %>,

                        <%# DataBinder.Eval(Container.DataItem, "[FirstName]").ToString() %></label>                           

            </ItemTemplate>

        </asp:Repeater>

    </fieldset>

</div>

I have this jQuery function:

$('input:checkbox[name=chkBox]').change(function () {           

            var id = $(this).attr('id');

            //var isChecked = $(this).attr('checked');  

            var isChecked = $('#'+id).is(':checked');     

});  

How do I get the id of the checkbox that has just been clicked and tell if it is checked or unchecked by the user as the result of the click action?

Thanks



Sumit Kesarwani

Total Post:378

Points:2694
Supported
Posted on    August-25-2014 2:12 AM

Hi Ankit, 

try this:

var isChecked = $(this).is(':checked');

var id = $(this).attr('id');


Don't want to miss updates? Please click the below button!

Follow MindStick