Currently, I am developing a todo list application that allows users to add to-do list items and search for specific tasks. My focus at the moment is on refining the search function. Presently, whenever a user searches for a name, only the first task associated with that person is displayed. However, the challenge lies in displaying all tasks related to that individual, as they may have multiple assignments. For example, if Bob has three different tasks, the current search functionality will only show the first one, whereas I aim to showcase all three. Does anyone have any suggestions or ideas on how to accomplish this?
function search() {
var searchTerm = document.getElementById("search").value;
searchTerm = searchTerm.trim();
if(searchTerm == null || searchTerm == "") {
alert("Please enter a string to search for");
return;
}
else {
var todoObj = undefined;
results = undefined;
re = undefined;
for(var i = 0; i < todos.length; i++) {
todoObj = todos[i];
re = new RegExp(searchTerm, "ig");
resultsOne = todoObj.who.match(re);
if(resultsOne) {
var ul = document.getElementById("test");
var li = document.createElement(li);
li.className = "listItem";
li.innerHTML = "You found " + todoObj.who + " who needs to " + todoObj.task;
ul.appendChild(li);
}
}
}
}