donglv9116 2018-08-07 21:04
浏览 78

回应从PHP到JavaScript的变量,并根据另一个字段更改一个字段

I am developing a website based on aviation, and one engine I run on my website, called SimBrief, must include the code below so that I can send the specifications along with the aircraft and registration.

<script>
var acdata = {};
acdata["reg":"YU-APA"]=['{icao":"A319","name":"A319-132","engines":"V2527\/A5","cat":"M","equip":"SDE2E3GHILORVWY","transponder":"H","pbn":"PBN\/B1D2D3","maxpax":"144","oew":92.48391898655717,"mzfw":128.9704233781548,"mtow":149.9143382857184,"mlw":137.78891386555,"maxfuel":42.086245851093594}'];
acdata["reg":"YU-APH"]=['{icao":"A320","name":"A320-232","engines":"V2527\/A5","cat":"M","equip":"SDE2E3GHILORVWY","transponder":"H","pbn":"PBN\/B1D2D3","maxpax":"174","oew":95.98926895529675,"mzfw":134.4819799327768,"mtow":162.0397627058868,"mlw":142.1981591092476,"maxfuel":42.086245851093594}']; 
</script>

Where YU-APA is an Airbus A319 and YU-APH is an Airbus A320.

<tr>
  <td>Aircraft:</td>
  <td>
    <select class="form-control" name="type" id="Aircraft" value="<?php echo "{$schedule->aircraft}"; ?>">                                                 
      <?php
      $equipment = OperationsData::getAllAircraftSingle(true);
      if(!$equipment) $equipment = array();
      foreach($equipment as $equip){
        echo '<option value="'.$equip->icao.'">'.$equip->icao.' - '.$equip->name.'</option>';
      }
      ?>
    </select>
  </td>
</tr>
<tr>
  <td>Registration:</td>
  <td><select class="form-control" name="reg" id="Registration">
    <option>YU-APA</option>
    <option>YU-APB</option>
    <option>YU-APC</option>
    <option>YU-APD</option>
    <option>YU-APE</option>
    <option>YU-APF</option>
    <option>YU-API</option>
    <option>YU-APJ</option>
    <option>YU-APH</option>
    <option>YU-APG</option>
    <option>YU-ARA</option>
    <option>YU-ALN</option>
    <option>YU-ALO</option>
    <option>YU-ALP</option>
    <option>YU-ALT</option>
    <option>YU-ALU</option>
    <option>YU-ALV</option>
    <option>YU-AND</option>
    <option>YU-ANI</option>
    <option>YU-ANK</option>
  </select></td>
</tr>

How can I make so that when I select "Airbus A319" in the Aircrafts dropdown, the YU-APA shows up in the Registrations dropdown, and when I select A320, the YU-APH appears? Obviously, there are more registrations for one aircraft.

  • 写回答

1条回答 默认 最新

  • dongzhan7253 2018-08-07 21:11
    关注

    Since you tagged jQuery:

    $(document).ready(function() {
        $("#Aircraft").change(function() {
            if($("#Aircraft").val() === 'A319') {
                $("#Registration").val('YU-APA').change();
            } else if($("#Aircraft").val() === 'A320') {
                $("#Registration").val('YU-APH').change();
            }
        });
    });
    

    NOTE: You need to add a value attribute to your Registration field <option> tags. Also, instead of typing A319 and A320 (in the if statement), type whatever the value is for those planes.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计