dimanche 31 janvier 2021

Problems with if statement in Javascript

This code is ment to be a simple ToDo-List.

I want the function InputCheck() to check if there is a value in the input bar. In case the bar is empty i want the function to not execute the addTodo-function. With the code like this it doesnt execute the function even if the input has a value .I dont know what´s causing it and i dont receive any errors. Any Ideas ? Thanks in advance.

const listButton = document.getElementById("ListButton");
const myList = document.getElementById("MyList");
const deleteButton = document.getElementById("Delete");
const doneButton = document.getElementById("Done");

listButton.addEventListener("click", InputCheck);

function InputCheck() {
  var input = document.getElementById("textValue").value;
  if (input == "") {
  } else {
    addTodo;
  }
}

function addTodo(event) {
  event.preventDefault();
  
  
  const toDoDiv = document.createElement("div");
  const newListItem = document.createElement("li");
  newListItem.innerHTML = document.getElementById("textValue").value;
  toDoDiv.appendChild(newListItem);
  toDoDiv.classList.add("ToDo-Div");

  

  const deleteButton = document.createElement("button1");
  deleteButton.classList.add("delete-btn");
  deleteButton.innerHTML =
    '<button id ="Delete" class="button">Delete</button>';
  toDoDiv.appendChild(deleteButton);

  
  const doneButton = document.createElement("button1");
  doneButton.classList.add("done-btn");
  doneButton.innerHTML = '<button id ="Done" class="button1">Done</button>';
  toDoDiv.appendChild(doneButton);

  myList.appendChild(toDoDiv);
}```

Aucun commentaire:

Enregistrer un commentaire