there is a list and input form (code attached below):
function someFunc() { var noh = document.getElementById("search").value; spsk = document.getElementById(listr); spsk.style.display = 'none' } document.getElementById("btn").onclick = someFunc;
.list li:nth-child { display: none; } input[type=button] { width: 120px; height: 25px; }
<input type="text" class="srch" id="search" onchange=""> <input type="button" id="btn" value="сортировать"> <ol class="list" id="listr"> <li>Саратов</li> <li>Новгород</li> <li>Москва</li> <li>Санкт-Петербург</li> </ol>
The task is as follows: There is a list in HTML, any tagged or ordered, when you enter a character (or part of a keyword), you must remove parts of the list that do not belong to them, that is, if you have a list attached in the code, write "m" in the input line , then only Moscow will remain, and all other parts of the list should be deleted, and if the entry line is cleared, the list will return to its original position.
The questions are as follows: 1. How to handle the input line and what can help with this? That is, if I enter and part of the list is deleted in my real-time mode, it means my value must be temporarily stored somewhere (I tried to store it, as seen by the JS code), and then somehow interact with the list, if so, how can I remove part of the list when I enter a certain character (what is it implemented and in what specific way)? If the value entered into the string does not need to be saved, how else can you implement the action “to do when changing?
I ask for help in solving this problem, because the Internet does not give clear answers, but it is argued that this is a "10-30 minutes" task, to which I have already killed more than two hours. Thank you in advance.
document.getElementById(listr)
- Here you have a typo - Stepan Kasyanenko<datalist>
HTML element in any modern online directory. - Inquisitor