I have this html code here:
<p id = "str">How much wood could a wood chip chop</p>
<br>
<input type = "text" value = "" id = "txt1"/>
<button onclick = "myFunction()"> Search </button>
<p id="demo">Display the result here.</p>
and a javascript code here:
function myFunction()
{
var myString = document.getElementById("str").innerHTML;
var myWord = document.getElementById("txt1").value;
var myPattern = new RegExp('.'+myWord,'g');
var myResult = myString.split(" ");
for(var i=0; i<myResult.length; i++) {
var result = myResult[i].match(myPattern);
if(result) break;
}
document.getElementById("demo").innerHTML = myResult;
}
Now what I want to do here is that:
when the user inputs
woo
it would outputwood
together with the number of results found like -2 results found
.when the user inputs
od
it would also outputwood
together with the number of results found like -2 results found
.Same with
ch
- which the output should bechip, chop
-2 results found
.And with
op
- which the output should bechop
-1 result found
.