簡體   English   中英

為什么是我的第二<select>標簽不顯示?

[英]Why is my second <select> tag is not showing up?

在選擇<select id="first_choice">中的選項之一后,我試圖顯示<select id="second_choice">標簽。 兩者都是從我的數據庫中選擇的。

技術員.php

<select name="cntNum" id="first_choice" class="form-control" onchange="fetch_select(this.value);" required>
  <?php 
    include('config.php');
    $query = "SELECT cntNum FROM contract";
    $result = mysqli_query($link,$query);
    while($row = mysqli_fetch_array($result)) {
      echo "<option>".$row{'cntNum'}."</option>";
    }                                                                                       
</select>
<select name="cntNum" id="second_choice" class="form-control" required></select>

Technical_fetch.php

require_once( 'config.php' );

$choice = mysqli_real_escape_string($_GET['choice']);
$query = "SELECT * FROM equipment WHERE cntNum = $choice";
$result = mysqli_query($link,$query);

while($row = mysqli_fetch_array($result)){
    echo "<option>" . $row{'cntNum'} . "</option>";
}

jQuery

<script>
  $("#first_choice").change(function () {
    $("#second_choice").load("technician_fetch.php?choice=" + $( "#first_choice").val());
  });
</script>

在編寫更多 HTML 之前,您需要關閉 PHP。

<select name="cntNum" id="first_choice" class="form-control" onchange="fetch_select(this.value);" required>
  <?php 
    include('config.php');
    $query = "SELECT cntNum FROM contract";
    $result = mysqli_query($link,$query);
    while($row = mysqli_fetch_array($result)) {
      echo "<option>".$row{'cntNum'}."</option>";
    }
  ?>
<!-- PHP must be closed if you then continue with HTML -->                                                                                       
</select>
<select name="cntNum" id="second_choice" class="form-control" required></select>

如果您只是在文件中編寫 PHP,那么您不需要關閉它,但如果您在它之后有不同的語言 (HTML),則必須關閉它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM