javascript - Character counter supposed to cut text off but does not when it is copied in -


i have character counter cuts off text , doesn't allow user keep typing once maximum limit has been reached. works when text being entered reason when text greater max copied in cuts off of text , means the count still greater max. displays 0 characters remaining when copied in when count characters still greter max.

function textcounter(field,field2,maxlimit) {   var countfield = document.getelementbyid(field2);  if ( field.value.replace(/\n/g, "\n\r").length > maxlimit ) {    field.value = field.value.replace(/\n/g, "\n\r").substring( 0,maxlimit).replace(/\n\r/g, "\n");  } else {   countfield.value = maxlimit - field.value.replace(/\n/g, "\n\r").length;  }  } 

above javascript function. when text copied in greater max cuts text off @ correct part form can submitted.

generally speaking, i'd take @ maxlength attribute.

http://www.w3schools.com/tags/att_input_maxlength.asp

specifically speaking, guess code not being executed "on paste", on keypress. on event fire textcounter? can provide code of text area?


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -