开发者

Converting special characters from Javascript to Java

开发者 https://www.devze.com 2023-03-25 17:13 出处:网络
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 `Sa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号