rreiss60
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("c omment");
var timer = 0;
var re = new RegExp("\\b(" + Object.keys(shortcuts).joi n("|") + ")\\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);
}
}
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("c
var timer = 0;
var re = new RegExp("\\b(" + Object.keys(shortcuts).joi
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
That's pretty cool, I like that.
ASKER