Я нахожусь в процессе обучения кодированию и мало знаю о JavaScript, поэтому у меня возникли некоторые проблемы и я буду признателен за любую помощь сообщества. У меня есть форма ввода и я хочу отключить кнопку отправки, пока не введено максимальное количество слов. У меня есть мой код как:
<script>
// Get reference to textbox
var input = document.getElementById("words");
// Add event handler for event that can be cancelled and prevent
// excessive data from ever getting into the textbox
input.addEventListener("keypress", function(evt) {
// Get value of textbox and split into array where there is one or
// more continuous spaces
var words = this.value.split(/\s+/);
// Get # of words in array
var numWords = words.length;
var maxWords = 8;
// If we are at the limit and the key pressed wasn't BACKSPACE or DELETE,
// don't allow any more input
if(numWords > maxWords) {
evt.preventDefault(); // Cancel event
}
</script>
<form action="" method="post "id="myform">
<div class="form-group">
<input id="words" data-max-words="8" data-announce="true"
class="words-data-form-control" type="text" name="wordlist"
wordlistlength="8"autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" required />
</div>
<div class="feedback-container">
<div class="feedback" style="display: none;"></div>
</div>
<div class="form-group">
<button class="btn btn-primary text-capitalize float-right"
id="submit" type="submit"
style="color: rgb(255,255,255);background-color: rgb(12, 108, 242);"
disabled>
<strong>submit</strong>
</button>
</div>
</form>