I'm just trying to create a simple button to check if an input field is empty and style it accordingly. I feel like this should be really simple but I'm just missing something.
<input id="text"></input>
<button id="button">check</button>
<script>
var text = document.getElementById('text');
var button = document.getElementById('button');
function checker() {
if (text.value === "") {
text.style.cssText = "background:red;";
return false;
}
else {
text.style.cssText = "background:green;";
}
}
button.addEventListener("click", checker(), false);
</script>
And here's the link to a jsfiddle that I was using to try and get it to work.