Link to home
Create AccountLog in
Avatar of rreiss60
rreiss60Flag for United States of America

asked on

JavaScript from JSFiddle

I found the following html and JavaScript on JSFiddle.  http://jsfiddle.net/qfmsy/1/

What code is needed to make this work in an html file I would create using notepad?


The code expands text from an abbreviation into full text.

html section:

<textarea id="comment" rows="20" cols="30"></textarea>

JavaScript Section:

shortcuts = {
    "cci": "customer called in",
        "rfc": "request for comments",
        "www": "world wide web"
}


window.onload = function () {
    var ta = document.getElementById("comment");
    var timer = 0;
    var re = new RegExp("\\b(" + Object.keys(shortcuts).join("|") + ")\\b", "g");



    update = function () {
        ta.value = ta.value.replace(re, function ($0, $1) {
            return shortcuts[$1.toLowerCase()];
        });
    }

    ta.onkeydown = function () {
        clearTimeout(timer);
        timer = setTimeout(update, 200);

    }


}
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rreiss60

ASKER

Dynamite!
That's pretty cool, I like that.