-1

出于某种原因,我的 java 脚本正在更改文本的颜色,但没有显示我的错误消息,任何帮助都会非常有用!

该代码是一个简单的 HTML 表单,要求提供考官姓名、编号、主题,还有一些单选按钮

<HTML>
<head>
<title>Exam entry</title>

<script language="javascript" type="text/javascript">

function validateForm() {
    var result = true;
    var msg="";

    if (document.ExamEntry.name.value=="") {
        msg+="You must enter your name \n";
        document.ExamEntry.name.focus();
        document.getElementById('name').style.color="red";
        result = false;
    }

    if (document.ExamEntry.subject.value=="") {
        msg+="You must enter the subject \n";
        document.ExamEntry.subject.focus();
        document.getElementById('subject').style.color="red";
        result = false;
    }

    if (document.ExamEntry.ExaminationNumber.value=="") {
        msg+="You must enter the Examination Number \n";
        document.ExamEntry.ExaminationNumber.focus();
        document.getElementById('Examination Number').style.color="red";
        result = false;
    }

    if(msg==""){
    return result;
    }

    {
    alert(msg)
    return result;
    }
}

</script>
</head>

<body>
<h1>Exam Entry Form</h1>
<form name="ExamEntry" method="post" action="S:\codes\success.html">
<table width="50%" border="0">
<tr>
        <td id="name">Name</td>
        <td><input type="text" name="name" /></td>
        <title>Exam entry</title>
    <tr>
        <td id="subject">Subject</td>
        <td><input type="text" name="subject" /></td>
    </tr>
    <tr>
        <td id="Examination Number">ExaminationNumber</td>
        <td><input type="text" name="Examination Number" /></td>
    </tr>
 <tr>
        <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
<tr>
        <td><input type="reset" name="Reset" value="Reset" /></td>
    <input type="radio" name="qualification" value="GCSE">GCSE<br>
    <input type="radio" name="qualification" value="AS">AS<br>
    <input type="radio" name="qualification" value="A2">A2<br>
</form>
</tr>
</table>
</body>
</HTML>
4

1 回答 1

2

ID 不能有空格.. 更改Examination Number为类似Examination_NumberExaminationNumber

修复了 jsFiddle 示例

于 2013-10-18T13:22:24.680 回答