please tell me I have a form within which one input and the "add" button ... everything works without a form, I click the add button and the element is added to the sheet! As soon as I create a form, when I press the button, I see that the element is somehow added and instantly disappears! here is my HTML:
<form id="zip"> <input type="text" id="candidate"/> <button type="submit" class="btnAdd" onclick="addItem()">Add</button> <ul id="places"></ul> </form> in ul id places these inputs should fit!
here's my js!
function addItem(){ var ul = document.getElementById("places"); var candidate = document.getElementById("candidate"); var li = document.createElement("li"); var btn = document.createElement("button"); btn.onclick = function() { var ul = document.getElementById("places"); var candidate = document.getElementById("candidate"); var item = document.getElementById(candidate.value); ul.removeChild(item); ul.removeChild(btn); } var t = document.createTextNode("delete"); btn.appendChild(t); btn.className = "btnDelete"; document.body.appendChild(btn); li.setAttribute('id',candidate.value); li.appendChild(document.createTextNode(candidate.value)); ul.appendChild(li); ul.appendChild(btn); } var form = document.getElementById("zip"); form.reset(); Help me please!