textbox text manipulation

textbox text manipulation

hi!
iwant a certain action to be done on keypress event and exactly on comma keypress (charcode=188).my application would be use to send txt message to multiple recipient(s) whose number(s) are comma separated.so basically on a textbox if a user type this 233,i need 233 to validate for network coverage from my sms gatewayand if this 233,244, i want this 244. i've come out with a code that does that but i need to make sure i'm doing the right thing if my site is stressed.so please check that for performance.the real problem is this.when a validate i want to highlight unsupported number (first in the textbox itself but don't know if i can) in by inserting it in a div whose id is valid and then apply a class to it. like
$('#valid').html().addClass('err');
but it's not working so i remove it.
here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" language="javascript" src="library/jquery-1.2.6.js"></script>
<script type="text/javascript" language="javascript" src="library/jqModal.js"></script>
<link rel="stylesheet" type="text/css" href="library/jqstyling.css" />
<style type="text/css">
.err { color: #ffffff}
</style>
<script language="javascript">
$().ready(function() {
  //$('#inputtxt').keyup(function(e){
//     var t = $(this).val();
//   //var te = t.indexOf(",");
//   //var to = t.substring(0,-1);
//   //var ti = e.charCode;
//   var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
//   if(key== 188)
//     $('#valid').html('<div >' +t+ '</div>');   
//  });
   var i = -1;
  $('#btn').click(function(){
 
     var y = $('#inputtxt').val();
   if(y.length!=0)
   {
      
      var n = y.substring(i+1,y.lastIndexOf(','));
      i = y.lastIndexOf(",");
      alert(i + ' ' + n);
      $.ajax({
         type:"POST",
         url:"try2.php",
         data:"name="+n,
         success:function(msg){
            if(msg=="true")
            {
               alert(msg);
               $('#valid').html("<div>man</div>");
            }
            
         }
      });
   }
   
  });
 
 
});
</script>
<title>Document sans titre</title>
<body>
<input type="text" id="inputtxt" />
<input type="button" id="btn" />
<br /><div id="valid" style="border:1pt solid;border-color:#FF6600;"></div>
</body>
</html>


ok if i insert the first one how would i append the second number div to it?don't really know.a real help would be very appreciated.really