• Post Reply Bookmark Topic Watch Topic
  • New Topic

inputTextArea limit characters

 
Mary Joe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have got an <h:inputTextarea
id="looking" cols="30" rows= "2"
value="#{LookingPage.lookingDetails}"
required="false"
onkeyup="this.value = this.value.substring(0, 100);" >
</h:inputTextarea>

I want to try and limit the number of characters entered, this is working fine with the onkeyup="this.value = this.value.substring(0, 100);" , the issue is if I try to edit any character it jumps to after the last existing character...any idea as to how to resolve this?

Thanks
 
Carlos Jorge Tavares Ferreira
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Maybe this will help you:

Limit textarea with countdown

Kind regards,

Carlos Ferreira
 
Mary Joe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This following resolved my issue


<t:inputTextarea value="#{testBean.testString}"
onkeyup="limitTextArea(this,100);"
onkeydown="limitTextArea(this,100);"
cols="30"
rows="2" />

<script>
function limitTextArea(element, limit) {

if (element.value.length > limit) {
element.value = element.value.substring(0, limit);
}

}

</script>

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!