WTAD Practical - 8
Write a JavaScript to find a string from the given text. If the match is found then
replace it with another string.
Write a JavaScript to find a string from the given text. If the match is found then
replace it with another string.
<HTML>
<html>
<HEAD>
<TITLE>WTAD.practical-8 @iAmLearningHere </TITLE>
</HEAD>
<body bgcolor="YellowGreen">
<font size="4">
<script language="javascript" type="text/javascript">
var c = prompt("Enter Text :");
var searchtxt = prompt("Enter Search Text :");
document.write("<br>Text is :: " + c );
document.write("<br>Search text is :: " + searchtxt);
var r = new RegExp(searchtxt);
if ( c.search() == -1)
{
alert("Match Not Found");
var searchtxt = prompt("Enter Search Text Again:");
}
else
{
alert("Match Found !");
var rtext = prompt("Enter Text To replace With:");
document.write("<br>Replace text is :: " + rtext);
document.write("<br>Replaced Text :: " + c.replace(r,rtext));
}
</script>
</body>
</HTML>
<html>
<HEAD>
<TITLE>WTAD.practical-8 @iAmLearningHere </TITLE>
</HEAD>
<body bgcolor="YellowGreen">
<font size="4">
<script language="javascript" type="text/javascript">
var c = prompt("Enter Text :");
var searchtxt = prompt("Enter Search Text :");
document.write("<br>Text is :: " + c );
document.write("<br>Search text is :: " + searchtxt);
var r = new RegExp(searchtxt);
if ( c.search() == -1)
{
alert("Match Not Found");
var searchtxt = prompt("Enter Search Text Again:");
}
else
{
alert("Match Found !");
var rtext = prompt("Enter Text To replace With:");
document.write("<br>Replace text is :: " + rtext);
document.write("<br>Replaced Text :: " + c.replace(r,rtext));
}
</script>
</body>
</HTML>
0 comments :