EasyBB
EasyBB

Reputation: 6574

Form Validation Hack character count

I am writing this code to count the characters inside the form. Though it works in the sense it's not actually counting I think. I keep getting the alert that it hasn't reached it's minimum count

$(function(){
  var minLength = 10;
  var form = $('form[action*="post"]');
form.submit(function (e) {
  var mini = $('#text_editor_textarea');
       if (mini.text().length < minLength) {
    alert ('You need to enter at least' +minLength + ' characters');
  e.preventDefault();
   }
   else if (mini.text().length > minLength) {
}
 });
});

Now my else if should pass I thought since really it has no restrictions within the statement whats wrong here?

Upvotes: 0

Views: 289

Answers (1)

bevacqua
bevacqua

Reputation: 48516

in your code, mini is the result of .val, which is a string. what you need, is to use mini.length

update: I meant

var mini = $(element).val().length;
// .val() gives the text, .length gives the string's length

Upvotes: 1

Related Questions