フォームの検証コードを書きました。
function checkWholeForm(theForm) {
// Create validation variables
var valid = true;
var validationMessage = "Please correct the following errors: \r\n";
// Validate name
if (document.getElementById('name').value.length == 0)
{
validationMessage = validationMessage + ' - Name is missing\r\n';
valid = false;
}
//(and there's a few other functions)
// Display alert box with errors if any errors found
if (valid == false)
{
alert(validationMessage);
}
return valid;
}
そして HTML ページでは、次のようになります。
<form action="submit.php" method="post" enctype="text/plain" onsubmit="return checkWholeForm(this)">
そして、表には次のとおりです。
<input type="text" id="name" name="name" size="20" value="" />
しかし、送信を押しても、空のテキスト ボックスではアラートがトリガーされません。私は何を間違っていますか?
編集:完全な HTML および JS については、 http: //jsbin.com/uvepin/2/editを参照してください。