I'm trying to add a piece of code that allows me to create a new case by pressing the Enter button. But when adding the code, everything stops working, and the error does not produce ..... please help))

window.onload = function(){ var todoList = []; var stored = localStorage.getItem('todo'); if (stored) todoList = JSON.parse(stored); out(); document.getElementById('add').onclick = function(){ var d = document.getElementById('in').value; var temp = {}; temp.todo = d; temp.check = false; var i = todoList.length; todoList[i] = temp; console.log(todoList); out(); localStorage.setItem('todo', JSON.stringify(todoList) ); localStorage.getItem('todo'); } createOnEnter: function(e) { if (e.keyCode != 13) return; if (!this.input.val()) return; Todos.create({title: this.input.val()}); this.input.val(''); } function out() { var out = ''; for (var key in todoList){ if (todoList[key].check == true){ out += '<input type="checkbox" checked>'; } else { out += '<input type="checkbox">'; } out += todoList[key].todo + '<br>'; } document.getElementById('out').innerHTML = out; } } 
  • createOnEnter: function(e) { - what is this piece of code? where did he come from? - Igor

1 answer 1

 function createOnEnter(e) { if (e.keyCode == 13) document.getElementById('add').click(); } window.addEventListener("keyup", createOnEnter); 
 <button id="add" onclick="console.log('AAA')">Add</button>