可能重复:
停止按下提交按钮,直到在文本区域中写入足够的单词
所以基本上我有下面的代码。我希望在文本区域中的字数超过 5 时启用提交按钮。下面的代码不起作用。想法?
<form method="post" id="writearticle" action="submitarticle.php">
<textarea rows="30" cols="85" id="content" name="content" placeholder="Write the article here. Try to abide by the instructions and keywords provided." onkeydown="checkWordCount();" ></textarea>
<br />
<input type="submit" id="submit" name="submitarticle" value="Submit Article" class="submit" disabled />
<script type="text/javascript">
function checkWordCount() {
var wordCount = document.getElementById('content').value.split(" ").length;
if (wordCount > 5) {
document.getElementById('submit').disabled = false;
} else {
document.getElementById('submit').disabled = true; alert("lol");
}
}
</script>
</form>