Write a script that inputs several lines of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text.

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CountIt</title>
<script type="text/javascript">
<!--
function search1()
{
var str1 = document.getElementById("string1").value;
var str2 = document.getElementById("string2").value;
var len=str1.length;
var count=0;
var search=str1.indexOf(str2);
for(i=0;i<len;i++)
{
if(parseInt(search)!= -1)
{
count++;
var search=str1.indexOf(str2,parseInt(search)+1);
}
}
document.getElementById("ans").value= str2 + " Occurs " + count + " times";
}
// -->
</script>
</head>
<body>
<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">&nbsp;</td>
<h1>Exercise 11.13 CountIt</h1>
<hr />

<p>Press F5 or Refresh to load script again. This is a program to determine the number of occurrences of the character in the text .</p>
<form name = "search" action = "">
<table border = "1">
<caption>Search</caption>
<tr><td>Enter any String</td>
<td><input name = "string1" type = "text" />
</td></tr>
<tr><td>Enter search Character</td>
<td><input name = "string2" type = "text" />
</td></tr>
<tr><td>Search Result</td>
<td><textarea name="ans">
</textarea>
</td></tr>
<tr><td><input type = "button" value = "SearchIt"
onclick = "search1()" /></td></tr>
</table>
</form>
</tr>
</table>

</body>
</html>