I've created a function to search for text within the jsTree framework.
The goal is to highlight the node if the search text is found. If not, inform the user with a message saying "No node matching the search string, please try again."
However, I'm facing an issue where even after entering a valid search text for the nodes, I still receive the alert on the browser window. Any suggestions on how to resolve this?
<script type="text/javascript">
function myFunction()
{
$(document).ready(function(){
var value=document.getElementById("search_field").value;
var searchResult;
var AlertsOn = false
$("#search_tree").click(function () {
searchResult=$("#tree").jstree("search",value);
if ($(searchResult).find('.jstree-search').length == 0)
{
AlertsOn = true;
}
else
{
AlertsOn = false;
}
if(AlertsOn == true){
alert($(searchResult).find('.jstree-search').length);
}
});
document.getElementById("search_field").value='';
});
}
</script>
html:
<fieldset id="search">
<input type="text" name="search_field" id="search_field" value="" />
<button id="search_tree" onclick="myFunction()"> Search</button>
</fieldset>