我有一个包含一些元素的列表。如何在此列表中加入强制性检查,因为任何主要浏览器都不支持select。
<th>From *</th>
<th><select name="from">
<option value="builder">Builder</option>
<option value="broker">Broker</option>
<option value="seeker">Seeker</option>
<option value="owner">Owner</option>
<option value="regular cf user">Regular CF user</option>
<option value="ams user">AMS user</option>
<option value="home needs user">Home Needs User</option>
</select>
</th>
这是我给出的列表,我想检查必填字段。
答案 0 :(得分:0)
在您发布表单后,只需检查该值,如果该值为空/缺失,则显示错误:
if (! isset($_POST['from']) || empty($_POST['from']))
{
// Deal with the fact that a mandatory field was not provided.
}
答案 1 :(得分:0)
使用javascript。
<th>From *</th>
<th><select name="from" onchange="return validate();">
<option value="">Select One</option>
<option value="builder">Builder</option>
<option value="broker">Broker</option>
<option value="seeker">Seeker</option>
<option value="owner">Owner</option>
<option value="regular cf user">Regular CF user</option>
<option value="ams user">AMS user</option>
<option value="home needs user">Home Needs User</option>
</select>
</th>
<强>的Javascript 强>
<script type="text/javascript>
function validate()
{
var from=document.getElementsByName('from').value;
if(from==""){
alert('Please select an option');
}
return true;
}
</script>: