vendredi 25 août 2017

Checkbox.Ischecked always gives false

My checkbox is always returning false. Can some one please help me.This is my html div.

     <div class="large-12 columns">
                                     <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

When the checkbox is checked, the page inspector code shows the following html snippet

    <div class="large-12 columns">


                                    <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox checked"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

When the checkbox is NOT checked, the page inspector code shows the following html snippet

    <div class="large-12 columns">


                                    <label for="Data_AlternatePhones[i]_IsPrimary">
                                        <input class="toggle_enabled hidden-field" id="Data_AlternatePhones[i]_IsPrimary" name="Data.AlternatePhones[i].IsPrimary" value="true" type="checkbox">
                                        <span class="custom checkbox"></span>
                                        <input name="Data.AlternatePhones[i].IsPrimary" value="false" type="hidden">IsPrimary
                                    </label>

                                </div>

My data variable in jQuery code is giving isPrimary = false in both case.

     var data =
            {
                customerGuid: $("#Data_CustomerGuid").val(),
                contactInfoType: type,
                contactInfo: $("#Data_AlternatePhones_"+i+"__PhoneNumber").val(),
                isPrimary: $("#Data_AlternatePhones_" + i + "__IsPrimary").is(':checked'),                   
                contactInfoID: $("#Data_AlternatePhones_"+i+"__ID").val()
            };

Please help me figure this out. Thank you.




Aucun commentaire:

Enregistrer un commentaire