The submit button is supposed to allow me to press it after I type something in the text field. However, It just stays greyed out. Any suggestions?
document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#submit").disabled = true;
document.querySelector("#task").onekeyup = () => {
if (document.querySelector("#task").value.length > 0) {
document.querySelector("#submit").disabled = false;
} else {
document.querySelector("#submit").disabled = true;
}
};
document.querySelector("form").onsubmit = () => {
const task = document.querySelector("#task").value;
const li = document.createElement("li");
li.innerHTML = task;
document.querySelector("#tasks").append(li);
document.querySelector("#task").value = "";
document.querySelector("#submit").disabled = true;
return false;
};
});
<h1>Tasks</h1>
<ul id="tasks"></ul>
<form>
<input id="task" placeholder="New Task" type="text" />
<input id="submit" type="submit" />
</form>