I have a text box and a submit button beside it. The button is in disabled state. Once the user type something in the text box, it should be enabled. That is working fine. But once the user starts typing, it gets enabled. And if backspace is used to make the field empty, the button still remains in enabled state.
<html>
<body>
<input type="text" id="fname" onkeyup="myFunction()">
<input type="button" id="a" disabled = "true" value ="click me">
<script>
function myFunction()
{
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
if(x.value != " ")
{
document.getElementById('a').disabled=false;
}
}
</script>
</body>
</html>
you should put else statement on your condition that makes the button disabled if textbox is empty. try the code below.