sorry, correction to my code posted above.
the cancel funciton has to have unbind() or it submits the
form
anyway, but even with the unbind, it then submits the form
twice the
next time the form is called.
cancel function above should read
pedalpete
View profile
More options May 8, 11:53 am
From: pedalpete <p... zifimusic.com>
Date: Thu, 8 May 2008 11:53:31 -0700 (PDT)
Local: Thurs, May 8 2008 11:53 am
Subject: unbinding, livequery or other way to cancel an ajax
retrieved
form or remove form from DOM?
Reply | Reply to author | Forward | Print | Individual
message | Show
original | Remove | Report this message | Find messages by
this author
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");
$(this).unbind();
});
};
[/code]
On May 8, 11:53 am, pedalpete <p... zifimusic.com> wrote:
> 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?
|