Replace The Bad Words!
by Taufik Nurrohman
HTML
<h2>Formulir</h2><textarea id="txt1" onkeyup="showText();">Eh, Eko Darpito bencong! Makan tuh tai biar sehat! Jangan kerjaannya nggaruk-garuk silit... Sok atuh. Dasar bencong. (PISSS!!! hehe)</textarea>
<h2>Tampilan</h2><div id="txt2"></div>
CSS
* {margin:0;padding:0}
body {padding:50px}
textarea {
width:100%;
height:120px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
margin:10px 0 10px;
}
div {
background-color:#eee;
padding:10px 15px;
margin:10px 0 30px;
}
JavaScript
function filterText(sText) {
return sText
.replace(/anjrit/ig, "alhamdulillah")
.replace(/kampret/ig, "kelelawar")
.replace(/bangsat/ig, "berbudi")
.replace(/maho/ig, "cewek perawan")
.replace(/bencong/ig, "pejantan tangguh")
.replace(/tai/ig, "vitamin")
.replace(/silit/ig, "kebun bunga")
.replace(/sontoloyo/ig, "subhanalloh")
.replace(/brot/ig, "ah...")
.replace(/waha+/ig, "yesss!");
}
function showText() {
var oInput1 = document.getElementById("txt1");
var oInput2 = document.getElementById("txt2");
oInput2.innerHTML = filterText(oInput1.value);
} showText();