Skip to Content
avatar image
Former Member

How to count the characters in textarea when typing? How to achieve in SAP CRM Web ui?

Hello Experts,

I have one requirement, Need to count the characters in the textarea field when typing.

strlen( ), this string operation only count the total characters. But My requirement need the count the characters when typing.

Kindly Help me with solution and Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jan 12, 2015 at 01:11 PM

    Hi Jagannadh,

    i will give one suggestion create 2 text area fields using  thtmlb:textArea tag here one is for note and another is for count...


    it looks like this..

    when ever your are changing the data in text box the count will vary..

    this is the sample code..

    <script type="text/javascript">

    var Count = null;

    function OnClick(onKeyUpTextArea) {

       if (Count == null) {

         thtmlbUtil.addEventHandler(onKeyUpTextArea, "keyup", myOnKeyUpHandler);

         Count = onKeyUpTextArea;



    function myOnKeyUpHandler() {

       if (Count) {

         var TextAreaID ="onKeyUp", "reporting");

         var reportingTextArea   = document.getElementById(TextAreaID);

         if (reportingTextArea) {

           reportingTextArea.value = Count.value.length;





       <htmlb:label for  = "Note"

                    text = "Type your data in Textarea/Textbox" />

    <br />

    <thtmlb:textArea id      = "onKeyUpTextArea"

                      text    = "Hello Experts..."

                      onClick = "OnClick(this);" />

       <htmlb:label for  = "Char"

                    text = "Character Left" />               

    <thtmlb:textArea id   = "reportingTextArea"

                      rows = "1"


    <br />

    Try this and let me know if you have any queries..

    Thanks & Regards,


    notepad.JPG (4.3 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Shaik,

      First of all Sorry for the late reply...

      In that case you have to get the standard text field ID (LINES) based on that count the characters which you have passed in the notes field and based on length have to rise the alert..

      this is the snippet code for that..


         data: lv_fieldname type string,

                 lv_contextnode type string,

                 lv_id type string.

                 lv_fieldname = 'links'.   " fieldname ( only small letters )

                 lv_contextnode = 'contextnode'.  " context node name in which the field is present.

         CONCATENATE controller->component_id '_' lv_contextnode '_' lv_fieldname INTO lv_id.

      <script type="text/javascript">

      var NoteID = document.getElementById("<%= lv_id %>");

      NoteID.addEventListener("keyup", myFunction);

      function myFunction() {

      var count ;

      count = document.getElementById("<%= lv_id %>").value;

      if(count.length == 10) {

      alert("Please enter less than 10 Chars ");


      // this is for display the count in input field...

      document.getElementById("NoteId").value = count.length;



      <thtmlb:textArea id   = "NoteId"

                        rows = "1"

                        text = "" />


      Srinivas. (386 B)