Both in the case I enter a string and in the case I leave the input box blank, I get the console.log("Something's wrong!"); The console.log of my fieldObj is in both cases shown empty.
I tried check if the content of an input-field is empty:
CODE:
let fieldObj = document.getElementById("newListItem").value;
let button = document.getElementById("addItem");
button.addEventListener("click", function() {
if (fieldObj != "") {
console.log(fieldObj);
console.log("Everything ok!");
} else {
console.log(fieldObj);
console.log("Something's wrong!");
}
}, false);
<input id="newListItem" type="text" />
<button id="addItem">Add</button>
I'd appreciate any help!