0

I have a text area in my form which accepts all possible characters from user. i restrict the character count entered in the textarea to 10 . When the user enters a text with special character say `SampleTxt’ the character count in textarea is 10. But when i get the value of text area in the form, the text becomes ‘SampleTxt’

and the count of the text becomes 21. How to over come this issue?

function toCount(in) {
    var inObj=document.getElementById(in);
    var re='/\r\n|\n|\r\|\f/g';
    var i=0;
    while(re.match(inObj.value)){i++;}
    var length=characters - (inObj.value.length+i);
    if(length <= 0) {
        inObj.value=inObj.value.substr(0,characters);
document.getElementById("remcount").innerHTML = inObj.value.length;
        }
    }

Jsp

< html:textarea property="descTxt" styleId="desc" onkeyup="toCount('desc');" />
DDK
  • 1,032
  • 18
  • 39
  • I think the answer to this question will help you: http://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript – aroth Aug 03 '11 at 06:05
  • @aroth even when i use unescape. i get this problem – DDK Aug 04 '11 at 07:19
  • Yes, because `unescape()` is the wrong function to use in this case. You need to use the `htmlDecode()` function described in the answer to the other question. – aroth Aug 04 '11 at 23:19

1 Answers1

0

It sounds like maybe you are getting the text of the textarea with o.innerHTML when you should be getting the text with o.value.

Post your actual code for more detailed help.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • i am getting the value of the textarea by using var txt = escape(document.getElementById("desc").value); – DDK Aug 04 '11 at 07:20