0

I have an html page with some checkboxes:

<div class="col-md-2">
        <div class='form-group employe-admin-contactP'>
            <input type="checkbox" class="readymade-checkbox admin" name="" id="admin-${member?.user?.id }" data-id="${member?.user?.id }"
                <g:if test="${member?.isAdmin()}">
                    checked
                </g:if>
            />
            <label for="admin-${member?.user?.id }" name="" class="readymade-label admin"></label>
        </div>
    </div>

Each time the user click on the checkbox (check/uncheck) a the following function which I wrote in js file have to be triggered:

$(document).ready(function() {
    $('.readymade-checkbox.admin:not(checked)').on('click',function(){
        var contact = {id:$(this).data('id') }
        $.ajax({
            url: makeUserAdmin,
            type: "post",
            data: {
                id: JSON.stringify(contact), companyId: $('#teamCompanyId').val()
            },
            success: function (data, textStatus) {
                jQuery("#updateCompanyteam").html(data);
            }
        })
        return false;
    });
})

The problem is that this the function is triggered only once.

Huangism
  • 16,278
  • 7
  • 48
  • 74
sarit rotshild
  • 733
  • 2
  • 10
  • 19
  • Could be related, you should use change instead of click. http://stackoverflow.com/questions/11205957/jquery-difference-between-change-and-click-event-of-checkbox – Huangism Mar 25 '15 at 14:25
  • Where are #updateCompanyteam and #teamCompanyId in your HTML? – bviale Mar 25 '15 at 14:31

1 Answers1

0

I bet that jQuery("#updateCompanyteam").html(data); will modify the HTML area of the checkbox ".readymade-checkbox.admin". You need a persistant listener for your click event (which will be available even if the DOM is modified), or to refresh your listeners. This issue has been already resolved in several threads like this one.

Cheers

Community
  • 1
  • 1
bviale
  • 5,245
  • 3
  • 28
  • 48