送信時に複数のテキストボックスに値があるかどうかをチェックするこの関数を作成しました。基本的には、JavaScript フォーム バリデーターです。空のテキスト ボックスがある場合、フォームは送信されず、必須フィールドがあることをユーザーに警告する必要があります。今、これは私にとっては完全に機能しますが、すでに値があり、フォームが送信された場合でも、送信する必要がありますが送信されません。errorString が空か null かどうかを確認する if ステートメントを作成しました。空である場合はフォームを送信する必要がありますが、空白の文字列でユーザーに警告します。コードはまだ if(errorString!=null || errorString=="") ステートメント内にあると思いますが、そうすべきではありません。
前もって感謝します
以下の私のコードを見てください:
function validateForm()
{
var txtTitle = document.forms["actionStepsForm"]["txtTitle"].value;
var txtRequestor = document.forms["actionStepsForm"]["txtRequestor"].value;
var txtReprocessingRequest = document.forms["actionStepsForm"]["txtReprocessingRequest"].value;
document.getElementById('rowCount').value = counter-1;
var errorString = "";
if (txtTitle==null || txtTitle=="")
{
errorString += "Title field is required. \n";
}
if (txtRequestor==null || txtRequestor=="")
{
errorString += "Requestor field is required. \n";
}
if (txtReprocessingRequest==null || txtReprocessingRequest=="")
{
errorString += "Reprocessing request FR is required. \n";
}
if (errorString!=null || errorString!="")
{
alert(errorString);
return false;
}
else
{
return true;
}
}
//implementation if HTML form
<form name="actionStepsForm" id="actionStepsForm" action="add_reprocessing.php?action=add" method="POST" onsubmit="return validateForm()">