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





<html>
<head>
<title>EX-8: WTAD : www.bipinrupadiya.com</title>
<script language="javascript">
var temp=new Array();
function findMyStr()
{
myStr=(document.getElementById("txt1").value);
str2bSearch=(document.getElementById("txt2").value);
myStr_length=myStr.length;
str2bSearch_length=str2bSearch.length;
for(i=0;i<myStr_length;i++)
{
temp[i]=myStr.substring(i,str2bSearch_length+i);
}
for(i=0;i<temp.length;i++)
{
if(temp[i]==str2bSearch)
{
found=true;
break;
}
else
{
found=false;
}
}
if(found==true)
document.getElementById("msg").innerHTML='String found ...';
else
document.getElementById("msg").innerHTML='string not found';
}
</script>
</head>
<body>
<br>Enter String : <input type="Text" ID="txt1">
<br>Search String : <input type="Text" ID="txt2">
<br><input type="button" value=" SEARCH" onClick="findMyStr()">
<div id="msg" style="color:red"></div>
</body>
</html>

1 comments:

Follow by Email

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.