bfinoradin
09-25-2010, 12:18 AM
I am altering a "bad word filter" for a silly project. Not looking to actually filter bad words. Here's what I have right now:
function filterText(sText) {
var rad1 = /dumb|lame/gi;
return sText.replace(rad1, "TOTALLY RAD!");
}
function showText() {
var oInput1 = document.getElementById("txt1");
var oInput2 = document.getElementById("txt2");
oInput2.value = filterText(oInput1.value);
}
So if the user types the words "dumb" or "lame" it is replaced by "TOTALLY RAD!"
The thing is, I want each word replaced to have it's own unique replacement word. I.e. "dumb" gets replaced by "cool" and "lame" gets replaced by "awesome"
Is there a way to define multiple replacements within sText.replace() similar to the way that I'm defining multiple words to be replaced: /dumb|lame/
I also tried just duplicating the var and return lines with their own unique var, etc. and that didn't work.
Am I approaching this from the wrong angle? Does it make more sense to use string?
This is how it will be implemented: http://benfinoradin.info/yes.htm
type into the top text box… try a sentence with "dumb" or "lame" in it.
function filterText(sText) {
var rad1 = /dumb|lame/gi;
return sText.replace(rad1, "TOTALLY RAD!");
}
function showText() {
var oInput1 = document.getElementById("txt1");
var oInput2 = document.getElementById("txt2");
oInput2.value = filterText(oInput1.value);
}
So if the user types the words "dumb" or "lame" it is replaced by "TOTALLY RAD!"
The thing is, I want each word replaced to have it's own unique replacement word. I.e. "dumb" gets replaced by "cool" and "lame" gets replaced by "awesome"
Is there a way to define multiple replacements within sText.replace() similar to the way that I'm defining multiple words to be replaced: /dumb|lame/
I also tried just duplicating the var and return lines with their own unique var, etc. and that didn't work.
Am I approaching this from the wrong angle? Does it make more sense to use string?
This is how it will be implemented: http://benfinoradin.info/yes.htm
type into the top text box… try a sentence with "dumb" or "lame" in it.