ruby on rails - jQuery character count onkeyup showing 1 character when 0 left -


i'm using jquery show characters remaining in text input , it's working fine when gets 0 characters remaining showing 1 though doesn't allow enter more. obvious , simple, it's stumping me today. here code i'm using:

= form.text_field :name, { required: true, class: "#{'error' if @project.errors[:name].present?}", placeholder: '40 characters max', maxlength: 40, :onkeyup => "countcharname(this)" } span id="charname" class="margin-left-5"                   function countcharname(val) {       var len = val.value.length;       if (len >= 40) {         val.value = val.value.substring(0, 40);       } else {         $('#charname').text(40 - len);       }     }; 

without testing it, assumption when reaches max length, input length 40. means if statement (len >= 40) true, else statement, updates $('#charname') remaining characters, doesn't run.

try changing if statement (len > 40)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -