views:

28

answers:

1

I have writed à checking/unchecking input code that works well in the fisrt loading of the page, but since I add an input via ajax then reload the inputs with the new input, the checking/unchecking event no longer works, I wonder what's the problem.

thanks before

A: 

that's the xhtml code

<div style="display: block;" id="regionLocalList">
    <div class="itemRegionCountry">
      <input type="checkbox" checked="checked" value="1" name="auteur[]" id="aucun">
      <label for="tous">no actor</label>
    </div>
    <div class="itemRegionCountry">
      <input type="checkbox" value="3" name="auteur[]" id="3">
      <label>others</label>
    </div>
    <div class="itemRegionCountry">
      <input type="checkbox" value="510" name="auteur[]" id="510">
    <label for=" Nick">Nick</label>
    </div>
    <div class="itemRegionCountry">
      <input type="checkbox" value="509" name="auteur[]" id="509">
      <label for="Craver">Craver</label>
    </div>

that's the check/uncheck jquey code

var othercheckboxes = $("#regionLocalList .itemRegionCountry input:not(#aucun)");
var aucun = $("#aucun");
$("#regionLocalInput").click(function(event) {
$("#regionLocalList").toggle();
                                            })
$(aucun).click(function(event) {
$(aucun).attr('checked',true);
$(othercheckboxes).attr('checked',false);
                                 });
$(othercheckboxes).click(function(event) {
                if (this.checked){
                $(aucun).attr('checked',false);
                                 }
$(othercheckboxes).each(function (i) {
            if ($(this).is(':checked')) {
            $(aucun).attr('checked',false);
            return false;
            }
            else 
            {
            return $(aucun).attr('checked',true);
            }
});
});

After adding the new input via a jqueryUI dialog, I retrieve the same xhtml above with a new input, after that I update the #regionLocalList div with html returned with ajax:

$("#regionLocalList").replaceWith(html);

the new input appeared but the event doesn't work

Amirouche Douda
Finally I found the solution, we can use the live() event to bind the new input, I invite you to follow this thread http://stackoverflow.com/questions/770308/events-not-registering-after-replacewith/2838259
Amirouche Douda