I want to disable the submit button if the text area is empty. I have initialized the submit button to disable condition and written bellow codes. But after typing text inside text area, it not got enable condition. Below are the codes. I have tried with If…else…condition also
<form id="breakdown">
<textarea id="tbd" placeholder="Enter breakdown details"></textarea>
<br>
<input type="submit" id="btn10" value="submit" disabled>
</form>
function disableEnableSubmitButton () {
let textarea1 = document.getElementById("tbd").value;
textarea1.addEventListener("input",change);
}
function change () {
document.getElementById("btn10").disabled = false;
}
2
Answers
I have used if...else...block also. It works fine.
The issue is that you have just created
JavaScript
functions and never called them anywhere. Which is why it is not changing the state of thebutton
.Here is the updated
script
to toggle thebutton
state: