views:

51

answers:

2

Need some help with a #jQuery issue. Can someone look at this - http://bit.ly/avGLl4 - and tell me where I went wrong?

A: 

Use the validate approach like:

var v = jQuery("#newsletterForm").validate({
    submitHandler: function(form) {
         var str =  $("#newsletterForm").serialize(); 
        $.ajax({
            type: "POST",
            url: "/_addNewsletterUser.php",
            data: str,
            success: function() {

                $('#newsletter_form').hide();
                $('#thankyounewsletter').show();

            }

        });
        return false;
    }
});
Pentium10
May want to note that this requires the validation plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
Nick Craver
This is nice but there remains the question of why the handler in the original question, which certainly looks like it should return false, is not preventing the form submission from continuing.
Pointy
@Pointy: It only validates, I tried it but wanted my error messages to have a custom look. Not sure I want to use that...was planning on it initially but I don't want to use it for this project.
pxjunkie
Thanks guys... went through the code line by line and it works now...
pxjunkie
A: 
$('#MyForm').submit(function(e){
    e.preventDefault();

    ...

i'd try that.

Brandon H
Trying that one
pxjunkie
According to the jQuery documentation, returning false from an event handler should be the same as calling preventDefault() and stopPropagation().
Pointy
i'd like it if "should be" meant "is"
Brandon H