1

I have an onclick event on all forms on the page:

$('form[method="post"]').click(function() {
    if($('textarea[name="serialized_data"]').length > 0) {
            alert("serialize_data already exists in this form!");
            return false;
        }
        var data=$(this).serialize();
        $(this).append('<textarea name="serialized_data">'+(data)+'</textarea>'); 
});

If you press a submitbutton and then on the target page press back in the browser, then this alert comes up.

But this solution stops on all forms.

How can I apply the alert only on the form that submitbutton was already pressed?

If you wonder why I input all data in that textarea, that is another question: compact all form-data with javascript

Community
  • 1
  • 1
rubo77
  • 19,527
  • 31
  • 134
  • 226

1 Answers1

1

You're selecting all textareas anywhere, instead of those within the clicked form. Try this:

$('textarea[name="serialized_data"]', this)

That restricts the selector to the context of this, which is the form.

Jason P
  • 26,984
  • 3
  • 31
  • 45