Tengo el siguiente script de autocompletado y tengo un cuadro de texto adicional donde quiero agregar varias acciones. El script funciona solo cuando necesito ingresar una acción. Agradeceré cualquier ayuda en:
al hacer clic en el elemento de la lista desplegable, aparece una nueva fila (similar a presionar la tecla Intro) para escribir la siguiente acción.
todo el proceso de bucle for para la finalización automática se inicializó nuevamente para que el usuario pueda elegir la siguiente acción de la lista desplegable.
Mi código funciona solo para una selección de acciones.
Este es el bucle for y el evento de clic que necesito modificar
for (i = 0; i < arr.length; i++) { /*check if the item starts with the same letters as the text field value:*/ if (arr[i][0].substr(0, val.length).toUpperCase() == val.toUpperCase()) { /*create a DIV element for each matching element:*/ b = document.createElement("DIV"); /*make the matching letters bold:*/ b.innerHTML = "<strong>" + arr[i][0].substr(0, val.length) + "</strong>"; b.innerHTML += arr[i][0].substr(val.length); /*insert a input field that will hold the current array item's value:*/ b.innerHTML += "<input type='hidden' value='" + arr[i][1] + "'>"; /*execute a function when someone clicks on the item value (DIV element):*/ b.addEventListener("click", function(e) { /*insert the value for the autocomplete text field:*/ inp.value = this.getElementsByTagName("input")[0].value; /*close the list of autocompleted values, (or any other open lists of autocompleted values:*/ closeAllLists(); });