Search This Blog

Thursday, 6 September 2012

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


Filename-js8.html

<html>
<head>
          <script language="javascript">
                   function check()
                   {                  frm.str1.value=frm.str1.value.replace(frm.str2.value,frm.str3.value);
                   }
          </script>
</head>
<body>
          <form name="frm">
                   Enter String
                   <input type="text" name="str1" />
                   Enter find String
                   <input type="text" name="str2" />
                   Enter replace string
                   <input type="text" name="str3" />
                   <input type="button" name="button" value="find" onClick="check()" />
          </form>
</body>
</html>

Output

Enter String  Enter find String  Enter replace string  

No comments:

Post a Comment