Hello I am trying to make a search bar to search anything which is available on a html page. I used window.find method.it highlights the string if its available in the html page. It returns a boolean value true or false. It gives false if the searched string is not available. But main problem is that it also returns false if all the searched strings are highlighted.Then how can I message the user that Nothing found OR searched text is already highlighted.
I also want to Search again if button clicked again also when all the searched text is highlighted .
I AM USING THIS CODE BUT ITS NOT COMPLETING MY ALL WISHES THAT I WANT.
JS
function SEARCH(){
var Search=document.getElementById("Search").value;
var result=window.find(Search);
if (result == false) {
alert("Nothing found or already highlighted "
); }
}
HTML
<input class="FLDS" type="text" id="Search" placeholder="Search" />
<button onclick="SEARCH()" id="SEARCHIT">SEARCH</button>
<p> A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or more sentences. Though not required by the syntax of any language, paragraphs are usually an expected part of formal writing, used to organize longer prose. </p>
I would recommend maybe trying to implement some PHP Ajax into your code and look at this link https://www.w3schools.com/php/php_ajax_livesearch.asp. If you're confused about how to do it reach out to me zackhitane@gmail.com and I can help you through it.