homepage Welcome to WebmasterWorld Guest from 54.166.113.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
need help for recursive text replace function
recursive text replace
tw56



 
Msg#: 4388688 posted 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

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



 
Msg#: 4388688 posted 10:08 pm on Nov 18, 2011 (gmt 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...

tw56



 
Msg#: 4388688 posted 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved