Action Script to java script - string to string translation

I need this, can it be added an option like, split and join again I don;t know that much of this but I saw an action script with that option it was " a,b,c " here is the actionscript code but I want it in javascript please help me get it...

tIn.onChanged = function()
{
    var sInput = tIn.text; //Gets the text from the first text field.
    sInput = translate(sInput); //Goes through the translator.
    tOut.text = sInput; //Sets the second text field to the translated text.
}
function translate(sInput)
{
    //This is where you add how you want your text changed.
    //It should be in the format of
    //sInput = searchAndReplace(sInput, What you want changed, What you want it changed             to);
//Remember to use quotes around the text you are changing.
    sInput = searchAndReplace(sInput, "how r u sis", "how are you sister ");
    sInput = searchAndReplace(sInput, "how r u bro", "how are you brother ");
    sInput = searchAndReplace(sInput, "whatsup ", "what is up ");
    return sInput;
}
function searchAndReplace(a, b, c) //Searches string a for b and replaces it with c
{
    tmp = a.split(b); //Splits a into an array of values where b is.
    a = tmp.join(c); //Joins them back together with c seperating them.
    return (a); //Returns the changed string.
}

Answers


First... if you want to execute the script while you type, you have no reason to add the "search" button. Anyway, here is the code on input field (as you type) AND on search button, chose what you want to use:

    <input id="sInput" type="text"  onkeydown="translate()">
    <input type="button" value="Search" onClick="translate()">

Than, AFTER this code and AFTER the div "result", you have to add the javascript code:

<script type="text/javascript">
    function translate()
    {
        var sInput = document.getElementById('sInput').value; 
        sInput = sInput.split("how r u sis").join("how are you sister ").split("how r u bro").join("how are you brother ").split("whatsup ").join("what is up ");
        document.getElementById('result').innerHTML =sInput;
    }
</script>       

Need Your Help

How to get active tab's value in variable of javascript?

javascript jquery html css

I have multiple tabs in li and each li contains class and id.And each tab has its own div which contains kind of some form.

How to disable "shake to undo" in iPhone application written with Phonegap?

iphone plist cordova

The only thing I've found is that you have to set UIApplicationSupportsShakeToEdit to false in plist file but it doesn't work for me.