Felipe
Felipe

Reputation: 147

Simplest form validation with the jQuery validation plugin wont work

I am trying to learn the jQuery validation plugin, so I created the simplest possible form, with the simplest possible validation code, but I still can't get it to work! When I click the submit button (leaving the field empty), I am sent to the default page as if the form had been submitted (the URL being "myurl.com/?name=") Below is the code, which I tried to do identical to that of a working tutorial.

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
    <script type='text/javascript' src='http://myurl.com/jquery.validate.js'></script>
    <script type='text/javascript' src='http://myurl.com/jquery.js'></script>

    <script type='text/javascript'>
    $(document).ready(function() {
        $("#test_form").validate();
    });
    </script>

    <script type='text/css'>
    label.error { color:Red; }
    </script>
</head>
<body>

<form id='test_form' action='' method='GET'>
    <p><label for='name'>Name</label><br />
    <input type='text' id='name' name='name' minlength='4' class='required' /></p>
    <p><input type='submit' value='Submit' /></p>
</form>

</body>
</html>

Upvotes: 0

Views: 229

Answers (1)

DarthJDG
DarthJDG

Reputation: 16591

You have to load the main jquery.js before the plugin jquery.validate.js. Scripts are loaded in the order they're parsed.

The above results in a script error when trying to load the validate plugin, as jQuery is not loaded yet, the jQuery object to extend doesn't exist at the time.

Upvotes: 1

Related Questions