After a user presses the send button, I want the send button to be disabled for 10 seconds. After the 10 seconds have elapsed, the button should be enabled again.
The setTimeout(resetMaterialTextfield(messageInputElement), 10000);
function doesn't seem to work below.
function onMessageFormSubmit(e) {
e.preventDefault();
// Check that the user entered a message that is a number between 1 and 100 and is signed in.
if (messageInputElement.value && checkSignedInWithMessage()) {
if (isNaN(messageInputElement.value)){
window.alert(" Please enter a number between 1 - 100 (inclusive) ");
}
else {
if (messageInputElement.value <= 0 || messageInputElement.value > 100){
window.alert(" Please enter a number between 1 - 100 (inclusive) ");
}
else {
saveMessage(messageInputElement.value).then(function () {
// Clear message text field and re-enable the SEND button.
setTimeout(resetMaterialTextfield(messageInputElement), 1000);
toggleButton();
});
}
}
}
}
And here is the other function:
function toggleButton() {
if (messageInputElement.value) {
submitButtonElement.removeAttribute('disabled');
} else {
submitButtonElement.setAttribute('disabled', 'true');
}
}
Grateful for any help please.
Thank you!