我的表格有一些问题(验证)。当没有给出数据时,它们不会给出任何错误。我该如何解决这个问题?这只是我的代码的一部分。对于字母、数字和电子邮件类型,它可以完美运行。谢谢您的帮助。
function onFormSubmit(form_element){
var checked = 0;
if (form_element.gender[0].checked == false && form_element.gender[1].checked == false){
alert("Please choose your Gender:Male of Female");
return false;
}
if (form_element.make.selectedIndex == 0){
alert("Please select your rating interval.");
form_element.make.focus();
return false;
}
if (form_element.click.checked == false){
alert("Please confirm your registration!");
false;
}
return true;
}
html
<form class="contact_form" action="" method="post" name="contact_form" onsubmit="return onFormSubmit(this)">
<ul>
<li>
<h2>Sign-Up Form</h2>
</li>
<li>
<label for="Male">Male:</label>
<input type="radio" name="gender" value="m" /> Female:<input type="radio" name="gender" value="f" />
<br />
</li>
<li>
<label for="National Rating">National Rating:</label>
<select name="make">
<option selected>-- SELECT --</option>
<option> Below 1200 </option>
<option> 1200 - 1500 </option>
<option> 1500 - 1800 </option>
<option> 1800 - 2100 </option>
<option> Above 2100 </option>
</select><br />
</li>
<li>
<input type="checkbox" name="click" value="regist"> I confirm my registration.
<br />
</li>
<li>
<button class="submit" type="submit">Submit</button>
</li>
</ul>
</form>
<div id="error_message" style="color:#ff0000;"></div>