[eluser]LuckyFella73[/eluser]
I set up the jquery validation by getting the .js files from
jquery.com and took the code from your post - everything
works fine (implemented in codeigniter). Maybe you have an error
in the lines you didn'd post. Here is my code for you to compare:
load url helper in controller file
view file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>jQuery validation</title>
<s-c-r-i-p-t src="<?php echo(base_url());?>jquery.js" type="text/javascript"></s-c-r-i--p-t>
<s-c-r-i-p-t src="<?php echo(base_url());?>jquery.validate.js" type="text/javascript"></s-c-r-i-p-t>
<s-c-r-i-p-t type="text/javascript">
$.validator.setDefaults({
submitHandler: function() { alert("submitted!"); }
});
$().ready(function() {
$("#login_form").validate({
rules: {
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
}
}
});
});
</s-c-r-i-p-t>
</head>
<body>
<form action="" id="login_form" name="login_form" method="post">
<input type="text" name="username" value=""><br />
<input type="password" name="password" value=""><br />
<input class="submit" type="submit" value="Submit"/>
</form>
</body>
</html>
Hope you find the error
EDIT:
I just noticed that the script does not work in IE 7. Having a look at
the code I found an error in the js rules section:
Remove the "," after closing the "password" rules.
"}," -> "}"