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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that was what I was searching for. It works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.