I have the following auto complete script and I have an textextra box where I want to add multiple stocks. The script is working only when I need to enter one stock. I will appriciate any help in:
when clicking on the item from the dropdown list, a new row (similar to pressing enter key) appear in order to write the next stock.
the whole for loop process for the auto complete initialized again that the user can choose the next stock from the dropdown list.
My code is working for only one stock pick.
This is the for loop and the click event I need to modify
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();
});