JavaScript Null Document Query Selector
Go to solution
Solved by Ciccioo,
-snip-
this could work:
first you check if there is an input, and if there is you remove its listener.
then you insert the new input
function f() { var last = document.querySelector("input[name=o" + num + "]"); //var last = document.getElementsByTagName("input").getElementsByName("o" + num)[0]; if(last) { last.removeEventListener('input', f); } // move on to generating the next input ++num; var node = document.createElement("div"); var input = document.createElement("input"); var span = document.createElement("span"); input.setAttribute("name", "o" + num); input.setAttribute("maxlength", "77"); input.setAttribute("placeholder", "Enter poll option..."); span.appendChild(document.createTextNode(num + 1 + ".")); node.appendChild(input) node.appendChild(span); document.getElementById("options").appendChild(node); input.addEventListener('input', f, false);}
edit: as for the boolean thing, you know that the last input of the page will never be inputted, because if it was then the script would generate another one which wouldn't be inputted
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now