使用onchange事件时如何使选择字段成为必需

时间:2018-11-26 06:02:49

标签: javascript php ajax select onchange

当我使用on change事件获取价值时,我以html格式选择字段必填选项不起作用。在选择“部门”字段但未选择“员工”字段时,正在提交表单。下面是我的代码,

</br><label for="Department" id="CustomID">
    Department
</label>
<select name="Department" id="Department" class="form-control" onChange="getemployee(this.value);" required="required">
    <option value="">Select Department</option>
    <?php $sql=mysqli_query($con,"select * from department");
      while($row=mysqli_fetch_array($sql))
      {?>
    <option value="<?php echo htmlentities($row['department']);?>">
        <?php echo htmlentities($row['department']);?>
    </option>
    <?php } ?>

</select>
</br><label for="employee" id="CustomID">
    Employee
</label>
<select name="employee" class="form-control" id="employee" required="required">
    <option value="">Select Employee</option>
</select>

0 个答案:

没有答案