1

テキストボックス(First_Name)が空のままの場合、エラーを作成しようとしています。たとえば、名のフィールドを空のままにすると、ユーザーは次のエラーを受け取ります。「名を入力してください」フィールドを空白のままにした後、送信ボタンをクリックしても何も起こりません...

<HTML>
<HEAD>
<TITLE>this is a test page</TITLE>
<script language="javascript" type="text/javascript">
<!--
function CheckForm()
{
  var formObj = document.getElementById("Data");
  var firstname = formObj.FIRST_Name.value;

    if(notEmpty(firstname, "Please enter your first name")){                        

    return true;}

    return false;
    }

function notEmpty(elem, helperMsg){
    if(elem.value.length == 0){
        alert(helperMsg);
        elem.focus(); // set the focus to this input
        return false;
    }
    return true;
}

</script>
</HEAD>
<BODY>
<div style="background: #CCCC99">
<HR><FORM id="Data" onsubmit="return CheckForm()" >
<P>First Name: <input type=text name=FIRST_Name maxlength=15 size=15>
</P>
<input type=submit value="Submit Products Registration Form" style="width: 220px"><input type=reset value="Reset">
</form>
</div>
</BODY>
</HTML>
4

1 に答える 1

2

firstnamenotEmptyは要素の値ですが、要素として渡す代わりに、

if(notEmpty(formObj.FIRST_Name, "Please enter your first name")){ 
于 2012-07-26T01:06:25.173 に答える