Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
todos list with a saved array and then retrieve it stuck?

i started an app todoslist , after creating first code simply of adding new todos in DOM now my task is this : addtodo : // grab todo value // pu tit in the array // tell the draw method to redraw the todos

drawtodo : grab the array for each text add a todo entry in the documen

the array my html code

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="style.css">
  <title>TodoList</title>
</head>

<body>
  <div class="todolist_box">
    <h3> To Do List </h3>
    <div class="input">
      <input type="text" id ="inp" placeholder="Add new Task">
      <button onclick="newTodo()" ><i> enter </i></button>
      <button onclick="newTodo()" ><i> save </i></button>
      <button onclick="drawtodo()" ><i> load </i></button>

    </div>
    <ul id="myUL">
    </ul>
  </div>
  <script src="script.js" type="application/javascript"></script>

</body>

</html>

and this is my javascript code

function newElement() {
  // this code doesn't work, but it gives you an idea
  const li = document.createElement("li")
  const newEntry = document.getElementById("inp").value
  const u = document.createTextNode(newEntry)
  li.appendChild(u)
  document.getElementById("myUL").appendChild(li)
  document.getElementById("inp").value = "Nothing"
  // something like thi
  let todos = [] 
  
  function newTodo() {
    let inpvalue = document.getElementById('inp').value 
    todos.push(inpvalue)
    // trigger draw event
  }


  function drawtodo() {
    for (var i = todos.length - 1; i >= 0; i--) {
      let li = document.createElement('li')
      let newlist = li.appendChild(document.createTextNode(todos[i]))
      inpvalue.appendChild(newlist)
        }
    
  }

  document.onload = function() {
    // this will excute when the document loads
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try using Javascript event listener instead of onclick attribute in html.

HTML:

<button id="load" ><i> load </i></button> // Removed onclick attribute

JS:

document.getElementById("load").addEventListener("click", drawtodo, false);

same with enter and save buttons, when click triggers the newTodo function.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda