简体   繁体   English

为什么单击提交按钮后仅选择选择标签的第一个值?

[英]Why is only first value of select tag selected after click submit button?

I just want to know why is only first value of select tag selected when I click submit button, though I select 2nd or more option? 我只想知道为什么虽然选择第二个或更多选项时单击提交按钮时仅选择选择标记的第一个值?

<div class="form-group my-3">
   <select class="form-control" name="role">
      <option value="">Select your role</option>
      <option value="1"  <?=(isset($_SESSION['role'])==1) ? 'selected': ''; unset($_SESSION['role']) ?> >Admin</option>
      <option value="2" <?=(isset($_SESSION['role'])==2) ? 'selected': ''; unset($_SESSION['role']) ?>>Modarator</option>
      <option value="3" <?=(isset($_SESSION['role'])==3) ? 'selected': ''; unset($_SESSION['role']) ?>>Editor</option>
   </select
<!-- error msg if role is not selected -->
    <?php if(isset($_SESSION['role_empty'])){ ?>
        <div class="alert alert-warning" role="alert">
           <?php echo $_SESSION['role_empty']; ?>
         </div>                    
    <?php } unset($_SESSION['role_empty']); ?>
</div>

I expect Editor or Modarator, but only I got Admin why? 我希望使用Editor或Modarator,但只有Admin为什么?

By default, <select> appears as a dropdown box, and only allows you to select one <option> element at a time. 默认情况下, <select>显示为下拉框,并且仅允许您一次选择一个<option>元素。 This can be overridden by using the multiple attribute, which tells the browser to render the element as a list box and allow for multiple items to be selected. 可以通过使用multiple属性来覆盖此属性,该属性告诉浏览器将元素呈现为列表框,并允许选择多个项目。 You can use Ctrl and left-click to select multiple elements manually. 您可以使用Ctrl并单击鼠标左键来手动选择多个元素。

 <select class="form-control" name="role" placeholder="Select your role" multiple> <option value="1" selected>Admin</option> <option value="2" selected>Moderator</option> <option value="3">Editor</option> </select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击提交按钮后如何保持下拉菜单的选定值 - How to remain selected value of dropdown after click on submit button 提交按钮后保留下拉菜单中的选定值 - Retain dropdown selected value after button submit 提交按钮后在下拉列表中显示选定的值 - Show selected value in dropdown after submit button 提交后保留选择标签的值-PHP - Retain Value of Select Tag after Submit - PHP jQuery选择器在单击提交按钮后未显示复选框的选定值,并且出现错误[object Object] - jQuery selector not showing the selected value of checkbox after click on submit button and i am getting error[object Object] 有没有一种方法来获取选择标签的值,而无需提交按钮或它只能在jQuery中 - is there a way to get the value of select tag without submit button or its only possible in jquery 如何<a>通过仅单击html中的提交按钮来自动</a>单击超链接( <a>标记)?</a> - How to click a hyperlink(<a> tag) automatically by clicking only a submit button in html? 单击按钮后保持选择值 - Keep option value selected after button click 单击提交后未填写完整表单,并且选择标记也不正确的值后,单选按钮未处于选中状态 - radio button is not staying checked after i click submit without filling the complete form, and select tag also not proper values 想要从“通过提交选择标签”按钮获取价值 - Want to get value from Select Tag by Submit button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM