Looking to set up a basic chat feature but struggling with clearing the input field when the send button is clicked. Additionally, I need to ensure that the send button remains disabled if the input field is empty. Here's what I've tried so far, but it's not working as expected.
function controlSendButton() {
btn.disabled = this.value.trim().length === 0;
}
text.addEventListener('input', controlSendButton, false);
controlSendButton.call(text);
$('#btn').on('click', function(e) {
e.preventDefault();
var val = $('#text').val();
if (val.length >= 1) {
$('#text').val("");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="sendCtrls">
<input type="text" autocomplete="off" placeholder="Your message is here" id='text'>
<button class="button button1" id="btn">Send</button>
</div>