Solved

JavaScript from JSFiddle

Posted on 2014-03-01
3
290 Views
Last Modified: 2014-03-01
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
Comment
Question by:rreiss60
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
<!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
 

Author Closing Comment

by:rreiss60
Comment Utility
Dynamite!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
That's pretty cool, I like that.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now