I have some JQuery form validation where im checking the length of the username is not long for the database but it seems to be returning true eveytime.
Am I missing something?
HTML
<form name="contact" method"post" action="">
<fieldset>
<label for="username" id="username_label" class="form_label">Username</label>
<input type="text" name="username" id="username" size="30" value="" class="text-input" />
<label class="error" for="username" id="username_error">This field is required. </label>
<label class="error" for="username" id="username_length">Your Username should be less than 30 characters.</label>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</fieldset>
</form>
JavaScript
$(function() {
$('.error').hide();
$(".button").click(function() {
// validate and process form here
$('.error').hide();
var username_length = $("input#username").val().length;
if (username_length < 30) {
$("label#username_length").show();
$("input#username").focus();
return false;
}
}
You are checking if unsername is shorter then 30, not longer!
note:
$("input#username")=>$('#username')