尝试在 html 和 php 中创建下拉列表时出现未知问题

制作一个新工具并需要一个下拉菜单,但它似乎不像我编码的那样工作。


不确定到底是什么问题。已经在网上研究过,但我一直无法弄清楚。


if(!isset($_POST["ReasonList"]))

 {

  $error .= '<p><label class="text-danger">Please select a reason</label></p>';

 }

<div class="form-group">

<label>Select Reason for Request</label>

<select id="ReasonList" name="ReasonList" class="form-control" value="<?php echo $ReasonList; ?>" />


  <option value = "">Select...</option>

  <option value = "1">Original Engineer has left the company</option>

  <option value = "2">Actively involved in field work on customer site</option>

  <option value = "3">No capacity due to customer mandated deadlines</option>

  <option value = "4">Exception request by manager</option>

</select>

</div>

如果选择了选项,则可以提交表单。如果没有选择选项,它会在 if 语句中给出错误 - 请选择一个原因


哈士奇WWW
浏览 155回答 1
1回答

慕的地6264312

查看更正后的<select>元素,以及代码缩进如何使 HTML 更易于阅读和调试。<div class="form-group">&nbsp; &nbsp; <label>Select Reason for Request</label>&nbsp; &nbsp; <select id="ReasonList" name="ReasonList" class="form-control">&nbsp; &nbsp; &nbsp; &nbsp; <option value = "">Select...</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value = "1">Original Engineer has left the company</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value = "2">Actively involved in field work on customer site</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value = "3">No capacity due to customer mandated deadlines</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value = "4">Exception request by manager</option>&nbsp; &nbsp; </select></div>该<select>元素没有value属性,并且您不小心关闭了<select>beforename属性。
打开App,查看更多内容
随时随地看视频慕课网APP