0

i want to replace the content of the textarea with the list of my "replacements". so that "Hi 23" is going to be "\u041D\u0456 23". whats my mistake?

$("textarea#comment").val(function(i, val) {
 return val.replace(/*the first letter (e.g. A)*/g, "*the second row e.g. \u0410*");
});

replacements = {
    "A": "\u0410",
    "B": "\u0412",
    "C": "\u0421",
    "H": "\u041D",
    "I": "\u0406",
    "J": "\u0408",
    "M": "\u041C",
    "O": "\u041E",
    "P": "\u0420",
    "S": "\u0405",
    "T": "\u0422",
    "V": "\u0474",
    "Y": "\u04AE",

    "a": "\u0430",
    "c": "\u0441",
    "e": "\u0435",
    "h": "\u04BB",
    "i": "\u0456",
    "j": "\u0458",
    "l": "\u04C0",
    "o": "\u043E",
    "p": "\u0440",
    "s": "\u0455",
    "y": "\u0443",
    "v": "\u0475";
}

1 Answer 1

2
var replacements = {
    "A": "\\u0410",
    "B": "\\u0412",
    "C": "\\u0421",
    "H": "\\u041D",
    "I": "\\u0406",
    "J": "\\u0408",
    "M": "\\u041C",
    "O": "\\u041E",
    "P": "\\u0420",
    "S": "\\u0405",
    "T": "\\u0422",
    "V": "\\u0474",
    "Y": "\\u04AE",

    "a": "\\u0430",
    "c": "\\u0441",
    "e": "\\u0435",
    "h": "\\u04BB",
    "i": "\\u0456",
    "j": "\\u0458",
    "l": "\\u04C0",
    "o": "\\u043E",
    "p": "\\u0440",
    "s": "\\u0455",
    "y": "\\u0443",
    "v": "\\u0475"
}

$("textarea#comment").val(function(i, val)
{
    val = val.split('');

    $.each(val, function(i,e){
        val[i] = replacements[e] ? replacements[e] : e;
    });

    return val.join('');
});

http://jsfiddle.net/6A2JG/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.