Page 1 of 1

Validation Plugin for jQuery

Posted: Mon Mar 14, 2011 4:18 pm
by CoolAsCarlito
I have a javascript error somewhere not sure where but also is this the correct way I should be using the validation plugin for anyone who has used it.

Code: Select all

$(document).ready(function() {
    $(document).ready(function() {
    $('div.message-error').hide();
    $('div.message-success').hide();
    
    $("#arenaForm").validate({ 
        rules: {
            arenaName: {
                required: true,
            },
            locationName: {
                required: true,
            },
        },
        messages: {
            arenaName: "Please enter a name for the arena!",
            locationName: "Please enter the arena's city and state!",
        },
        submitHandler: function(form) {
            form.submit();
            var userID = $("input#userID").val();
            var arenaName = $("input#arenaName").val();
            var locationName = $("input#locationName").val();
            var dataString = 'userID=' + userID + '&arenaName=' + arenaName + '&locationName=' + locationName + '&submitArena=True';
            $.ajax({
                type: "POST",
                url: "processes/arenas.php",
                data: dataString,
                success: function(myNewVar) { 
                    if (myNewVar == 'good') {
                        $('div.message-error').hide();
                        $("div.message-success").html("<h6>Operation successful</h6><p>" + arenaName + " was saved successfully.</p>");
                        $("div.message-success").show().delay(10000).hide("slow");
                        $(':input','#arenaForm')
                        .not(':submit, :hidden')
                        .val('')   
                    } else {
                        $('div.message-success').hide();
                        $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + arenaName + " already exists in the database.</p>");
                        $("div.message-error").show();    
                    }
                }
            });
            return false;    
         }
    });
});
});

Re: Validation Plugin for jQuery

Posted: Mon Mar 14, 2011 4:31 pm
by pickle
Never used the plugin, but the Javascript error console should tell you where the error is. If you're doing Javascript work, you should definitely use the Firebug add-on.

Re: Validation Plugin for jQuery

Posted: Mon Mar 14, 2011 5:16 pm
by CoolAsCarlito
I found the issue it was missing a comma after a closing curly brace however is there anyone that has used the plugin that could see if I'm using it correctly.

Another thing is that after the js error goes away it does this in the URL: myurl ?arenaName=Riverfront+Community+Center&locationName=Leavenworth%2C+Kansas&userID=1&submitArena=Submit+Arena#

Why is that?

I updated my code.