Monday, 17 June 2013

8. Write a JavaScript to find a string from the given text. If the match is found then replace it with another string.

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.




<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>



WTAD practical 8

For all WTAD programs wtad-pra cticals.html
To get all programs in your inbox.Enter your email

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT