Here in this code I’m trying to disable the upload button when input is entered in text-box & when the text-box is empty upload button should be enabled, but here I’m doing exactly opposite to my desired results, it enables the button when input is provided and disables the button when no input is provided.
JS
<script>
$(document).ready(function () {
$("#textbx").keypress(function () {
if ($("#textbx").val().length > 0) {
$("#myFile").attr("disabled");
}
});
$("#textbx").blur(function () {
if ($("#textbx").val().length == 0) {
$("#myFile").attr("disabled", "disabled");
}
});
});
</script>
HTML
<input id="textbx" type="text" />
<input type="file" id="myFile" name="filename" />
2
Answers
set disabled to true to deactivate and false to reactivate
am using jQuery v3.6.3 in this example