Welcome visitor
* Login
* Register
It is currently March 24th, 2019, 2:51 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » HTML



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  replace special characters
PostPosted: June 4th, 2009, 7:24 am 
User avatar

Posts: 37
does anyone have a code to replace characters like "<" and ">" from a text typed on a textarea? thanks.


Top
 Profile  
 
  Re: replace special characters
PostPosted: June 4th, 2009, 7:32 am 

Posts: 55
What language are you using? Because you posted here I think you are not using PHP, and if so, I think this can be useful as well
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
    function sym(el){
    var res="";
    var l="";
    var i; i=0;
    var s= document.getElementById(el).value;
    while (i<=s.length){
    var l= s.substr(i,1);
    switch(l){
    case '<':
        l = '&lt;';
        res = res + l;
        break;
    case '>':
        l = '&gt;';
        res = res + l;
        break;
    default:
        res = res + l;
    }
    i++;
    }
    }
    </script>
</head>
<body>
<textarea id="area" onchange = "sym(id);"></textarea>
</body>
</html>

HTH.


Top
 Profile  
 
  Re: replace special characters
PostPosted: June 4th, 2009, 8:17 am 
User avatar

Posts: 37
thank you so much!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Client Side » HTML


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron