简体   繁体   中英

Converting special characters from Javascript to Java

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');" />

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM