Re: Javascript Replace
HTML:
<div id="text">Hello my name is John Smith</div><button onclick="tmod('text')">Click</button>
Javascript:
function tmod(id){
var str = document.getElementById(id).innerHTML;
str = str.replace("is","was");
str = str.replace("Hello","Hi");
document.getElementById(id).innerHTML = str;
}
Oh and for a text box, it'll be
HTML:
<input type='text' id="text" value="Hello my name is John Smith" /><button onclick="tmod('text')">Click</button>
Javascript:
function tmod(id){
var str = document.getElementById(id).value;
str = str.replace("is","was");
str = str.replace("Hello","Hi");
document.getElementById(id).value = str;
}
Last edited by scopey; 10-07-2009 at 03:32 PM.
- When in doubt, refer to the PHP manual.