Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!