[jQuery] unbinding, livequery or other way to cancel an ajax retrieved form or remove form from DOM?

[jQuery] unbinding, livequery or other way to cancel an ajax retrieved form or remove form from DOM?


Hi All,
I'm building a site with lots of ajax retrieved forms, and have
finally realized why I'm seeing tons of errors (I think).
On the site, if you select an input which gets an ajax form, I add a
'cancel' button to the form which will hide the form if the user
decides not to take that action.
However, if the user then decides to go back and fill out that form
later, when they submit the form, it submits twice once without any
parameters, but that may be of no consequence if it only submits for
the form the user intends to submit.
wherever I retrieve the form initially, i use .livequery so the dom is
always up to date.
[code]
$(".addReq").livequery('click', function(event) {
        var id = this.id;
        var formID = "#addReqForm"
                    $(formID).fadeIn("slow").html(loading);
            $.ajax({
                type: "POST",
                url: "processes/addRequests.php",
                data: id,
                success: function(response){
                    $(formID).html(response);
                    cancelForm(formID);
                    addReqSubmit();
                    }
            });
    });
[/code]
the 'cancelForm' function looks like this
[code]
    function cancelForm(formID){
            $(formID).append('<input type="submit" class="cancel"
value="cancel">');
            $(".cancel").click( function(){
                $(formID).fadeOut("slow");
                });
            };
[/code]
I have tried attaching the following actions to the cancel.click
action
1) .livequery
2) $(this)unbind()
3) $(this).children().remove()
4) return false;
but so far no luck. Anybody have a simple way to remove a form from a
page which actually results in it's complete removal?















































    • Topic Participants

    • pete