Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: open

Message Too Old, No Replies

need help for recursive text replace function

recursive text replace

     

tw56

9:29 pm on Nov 18, 2011 (gmt 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;
}

penders

10:08 pm on Nov 18, 2011 (gmt 0)

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



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...

tw56

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month