Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: open

Message Too Old, No Replies

need help for recursive text replace function

recursive text replace

     
9:29 pm on Nov 18, 2011 (gmt 0)

New User

joined:Nov 9, 2011
posts:19
votes: 0


I have to change the german character over on the php side before sending them back through ajax. That all works fine and I can make the change on the javascript side but it only gets the first occurance.
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var txt=xmlhttp.responseText;
txt=txt.replace("0000","");
txt=txt.replace("1111","");
txt=txt.replace("2222","");
txt=txt.replace("3333","");
document.getElementById("myDiv").innerHTML=txt;
}
10:08 pm on Nov 18, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


Try passing a RegExp with the global modifier (g), rather than an ordinary string, as the first argument to the replace() method...

txt = txt.replace(/0000/g,"");

etc...
11:32 pm on Nov 18, 2011 (gmt 0)

New User

joined:Nov 9, 2011
posts:19
votes: 0


Wow, thanks penders. That worked. I tried building several complex functions but was not getting anywhere.