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)

10+ Year Member



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 10+ 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)

10+ Year Member



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