Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: why replace function only replaces once?


Message #1 by "ejaz" <ejaz@p...> on Wed, 24 Jul 2002 07:36:06 +0500
 Hi Ejaz,

> I have a problem that when i insert a text in textarea by clicking a
button
> it alwasy add the text at the end of the line, if i try to insert the text
> i.e (k) in between the words it doesnt work...Second problem is when i
> compile the textarea code and use replace function it only replaces one
time
> as shown below in the code if the text="(k)(k)(k)(k)(k)" it shows a
picutre
> sick.gif only once.
> pls tell me how to overcome this problem
> regards....
>
> <INPUT TYPE="button"
>
ONCLICK="document.Encrypt.normal.value=document.Encrypt.normal.value+'(k)';"
> VALUE="kiss">
>
> <TEXTAREA style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY:
> verdana,arial,helvetica; BACKGROUND-COLOR: #edebeb" name=normal rows=15
> cols=100 size="9">Enter here the Text to be Encrypted</TEXTAREA>
>
>
> var text=Encrypt.normal.value;
> text=text.replace("(k)","<img src='emoticons/sick.gif'>");
> text=text.replace("(l)","<img src='ff.gif'>");
> document.write ("<b><font size='3'>"+text);
> document.write ("</font></b>");

The first parameter of the replace function is treated as a regular
expression, so you can use something like...

text=text.replace(/\(k\)/g, "<img src='emoticons/sick.gif'>");
text=text.replace(/\(l\)/g, "<img src='ff.gif'>");

HTH,

Chris



  Return to Index