• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

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);

    }


}
0
rreiss60
Asked:
rreiss60
1 Solution
 
GaryCommented:
<!DOCTYPE html>
<html>
<head></head>
<body>
<textarea id="comment" rows="20" cols="30"></textarea>

<script>
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);

    }
} 
</script>
</body>
</html>

Open in new window

0
 
rreiss60Author Commented:
Dynamite!
0
 
Dave BaldwinFixer of ProblemsCommented:
That's pretty cool, I like that.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now