Code:
<html>
<head>
<script>// REPLACE VARIABLE VALUE IN TEXTBOX OR TEXTAREA OR DIV BY ANOTHER VALUE
function doRep(elm, val2replace, change2) {
var txt = (elm.value||elm.innerHTML),
// setting regex with val2replace global and case insensitive
match = new RegExp(val2replace.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1"), 'gi'),
output = txt.replace(match, change2); // replacing variable string with variable replacement value
elm[ (elm.select===undefined) ? "innerHTML" : "value" ] = output;
}
</script>
</head>
<body>
<input type=text id=txt1 value="Now is the time for all good men to come to the aid of their country." size=70>
<br> <br>
<textarea id=txt2 cols=40 rows=5>Now is the time for all good men to come to the aid of their country.</textarea>
<br> <br>
<div id=divText>Now is the time for all good men
<br>to come to the aid of their country.</div>
<br>
Find:
<input type=text id=txt2find >
<br>Replace:
<input type=text id=reptext >
<br>
<br>
<br>
<button onclick=doRep(txt1,txt2find.value,reptext.value)>Textbox: Do it</button>
<button onclick=doRep(txt2,txt2find.value,reptext.value)>Textarea: Do it</button>
<button onclick=doRep(divText,txt2find.value,reptext.value)>DIV: Do it</button>
</body>
</html>
tested: IE10/7,FF, CH