我正在尝试这样做,以便当用户在 textarea 中键入超过 10 个单词时,启用提交按钮。下面是我的代码摘录。即使那里有 10 多个单词,它也不让我提交。任何帮助,将不胜感激。
<?php
if($auth = 1)
{
echo "<center><h1>Write Article</h1><br /></center>";
echo "<form method=\"post\" action=\"processarticle.php\" id=\"myform\" >";
echo "<b>Keywords:</b> " . $array['keywords'];
echo "<br />";
echo "<b>Purpose:</b> " . $array['purpose'];
echo "<br />";
echo "<b>Style:</b> " . $array['style'];
echo "<br />";
echo "<b>Instructions:</b> " . $array['instructions'];
echo "<br />";
echo "<b>Length:</b> " . $array['length'];
echo "<br />";
echo "<hr>";
echo "<textarea rows=35 cols=85 name=\"content\">";
echo "</textarea>";
echo "<br />";
echo "<input type=\"hidden\" name=\"refferer\" value=\"1\" />";
echo "<input type=\"hidden\" name=\"articleid\" value=\"" . $arid . "\" />";
echo "<input type=\"hidden\" name=\"articletitle\" value=\"" . $articletitle . "\" />";
echo "<input type=\"submit\" value=\"Submit Article\" id=\"submit\" name=\"submit\" />";
echo "</form>";
}
?>
<br /><br /><br />
<!-- /main -->
</div>
<!-- content -->
</div>
<!-- /content-out -->
</div>
<!-- footer -->
<?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?>
</body>
<script type="text/javascript">
$('#myform').submit(function(event) {
var text = $("#content").val();
text = text.split(" ");
// check for at least 10 words
if(text.length < 10){
// prevent submit
event.preventDefault();
return false;
}
});
</script>