Help

Discussion in 'JavaScript' started by zurc, Mar 2, 2007.

  1. #1
    Hi I have a textbox then if a user inputs a string on the box then it detects special characters it change them to something else.... does anybody have a script for that
     
    zurc, Mar 2, 2007 IP
  2. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Use the following function to replace the characters.
    Populate the arrays arReplace and arReplaceWith with the required characters.
    
    var arReplace = new Array('a', 'b', 'c', 'd', 'e');
    var arReplaceWith = new Array('A', 'B', 'C', 'D', 'E');
    function replace(str){
    	len = arReplace.length;
    	for(i = 0; i < len; i++){
    		str = eval('str.replace(/' + arReplace[i] + '/g,  arReplaceWith[i] )');
    	}
    	return str;
    }
    
    Code (markup):
     
    Aragorn, Mar 2, 2007 IP