function changeText(elmid, badword, goodword, optionid) { textBlock = document.getElementById(elmid); regex = new RegExp('\\b' + badword + '\\b', 'g'); textBlock.value = textBlock.value.replace(regex,goodword); option = document.getElementById(optionid); option.style.display = 'none'; }