phtm文件列表中的必选检查字段


Mandatory Check field in a list in phtm file

我有一个包含一些元素的列表。既然大多数浏览器都不支持select required,我怎么能把mandatory check放到这个列表中呢

<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>

这是我的给定列表,我想检查的强制性字段

POST表单后,只需检查值,如果为空或缺失,则显示错误:

if (! isset($_POST['from']) || empty($_POST['from']))
{
    // Deal with the fact that a mandatory field was not provided.
} 

使用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>: