Validation Plugin for jQuery

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Validation Plugin for jQuery

Post 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;    
         }
    });
});
});
Last edited by CoolAsCarlito on Mon Mar 14, 2011 5:16 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Validation Plugin for jQuery

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
CoolAsCarlito
Forum Contributor
Posts: 192
Joined: Sat May 31, 2008 3:27 pm
Contact:

Re: Validation Plugin for jQuery

Post 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.
Post Reply