#searchName
не имеет значения при загрузке страницы, и вы не обновляете значение внутри функции, таким образом, если условие не выполняется.
Вы должны принять значение поиска внутри функции.
const list = document.getElementById('list');
const userAction = async (event) => {
list.innerHTML = ''; //clear the content on each click
event.preventDefault();
const searchName = document.getElementById('searchName').value.trim();
fetch('https://jsonplaceholder.typicode.com/todos')
.then(response => response.json())
.then(todos => {
todos.forEach((todo) => {
if(searchName == todo.title){
const li = document.createElement('li');
li.textContent = `${todo.userId} ${todo.id} ${todo.title} ${todo.completed}`;
list.appendChild(li);
}
});
})
}
<form method="POST">
<input type="text" id="searchName" class="form-control" placeholder="Lorem name">
<button onclick="userAction(event)" class="search-icon"><img src="images/icon.png" alt="submit"></button>
</form>
<ul id="list">
</ul>