简体   繁体   中英

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?

By default, <select> appears as a dropdown box, and only allows you to select one <option> element at a time. 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. You can use Ctrl and left-click to select multiple elements manually.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM