简体   繁体   中英

PHP Select from drop-down

I can't select the top option from the drop-down only the options under the top.

<form>
    <select name="car_license" class="form-control" id="car_license" onchange="change()">
        <?php for ($i = 0; $i < $size; $i++) { ?>
            <option value="<? echo $data[$i]['license'] ?>"><? echo $data[$i]['license'] ?></option>
        <? } ?>
    </select>
</form>
    
<script>
    function change(){
        document.getElementById("myform").submit();
    }
</script>

$license = $_POST['car_license'];

Your code seem not complete but will suggest you try this.

 <form method="post">
   <select name="car_license" class="form-control" id="car_license" 
    onchange="change()">
   <?php for ($i = 0; $i < $size; $i++) {
    ?>
    <option value="<? echo $data[$i]['license'] ?>"><? echo $data[$i] 
     ['license'] ?></option>
  <? } ?>
   </select>
</form>

   <script>
       function change(){
       //use ajax to submit using "post" method
       }
  </script>

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