I have the following code. It can just replace the first occurrence of a string. I need to replace all the same strings in the text. Could you somebody tell me how to modify the function replaceString() using a loop struction? Thanks a lot in advance for your kind help.
<HTML>
<HEAD>
<TITLE>Replacement method</TITLE>
<script language="JavaScript">
function replaceString(regexpression, replaceString){
document.replaceForm.source.value =
document.replaceForm.source.value.replace
(regexpression, replaceString)
}
</script>
</HEAD>
<BODY>
<form name=replaceForm>
<textarea cols=45 rows=5 name=source>
In teh tree-tier client/server architecture,
teh business logic is separated into a
middle tier: an application server is used
to manage teh business logic, and a database
server handles the data access logic, and
the client manages only the presentation
logic
</textarea>
<br><br>
Replace:<input type=text name=toReplace size=10>
with:<input type=text name=replaceWith size=10>
<input type=button value="Replace"
onClick="replaceString(toReplace.value,replaceWith.value)">
</form>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Replacement method</TITLE>
<script language="JavaScript">
function replaceString(regexpression, replaceString){
document.replaceForm.source.value =
document.replaceForm.source.value.replace
(regexpression, replaceString)
}
</script>
</HEAD>
<BODY>
<form name=replaceForm>
<textarea cols=45 rows=5 name=source>
In teh tree-tier client/server architecture,
teh business logic is separated into a
middle tier: an application server is used
to manage teh business logic, and a database
server handles the data access logic, and
the client manages only the presentation
logic
</textarea>
<br><br>
Replace:<input type=text name=toReplace size=10>
with:<input type=text name=replaceWith size=10>
<input type=button value="Replace"
onClick="replaceString(toReplace.value,replaceWith.value)">
</form>
</BODY>
</HTML>