如何在不提交和从数据列表中搜索的情况下从输入中获取价值

Posted

技术标签:

【中文标题】如何在不提交和从数据列表中搜索的情况下从输入中获取价值【英文标题】:How to get value from input without submitting and search it from datalist 【发布时间】:2018-05-24 02:50:17 【问题描述】:
> This Is My html CODE

<label>Person</label>
<input name="PersonID" type="text" id="PersonID">

<label>Car Plate Number</label>
<input name="PersonsCarPlateNumber" list="PersonsCarPlateNumber" type="text" />

> This is My php CODE

<?php
$conn = mysqli_connect("localhost", "root", "", "PersonWithCars");
$result = $conn->query("SELECT CarPlateNumber FROM Persons WHERE ID = '***PERSONID***' ");
?>

> This Is My Data List Where The Search For Persons Car

<datalist id=PersonsCarPlateNumber>
<?php while ($row = $result->fetch_assoc()):?>
<?php unset($CarPlateNumber);
$CarPlateNumber = $row['CarPlateNumber'];?>
<option value="<?php echo $CarPlateNumber?>"></option>
<?php endwhile;?>
</datalist>   
    需要帮助对不起我的代码搞砸了只是一个初学者在这里学习 PersonID,PersonsCarPlateNumber

【问题讨论】:

可以通过ajax实现。 各位高手能给我一段代码我可以参考吗? openenergymonitor.org/forum-archive/node/107.html 【参考方案1】:
<!-- date picker -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>
  $( function() 
    $( "#datepicker" ).datepicker();
   );
  </script>

<!-- 2 decimal places -->
<input onchange='fixit(this)'>
<script>
  function fixit( obj ) 
    obj.value = parseFloat( obj.value ).toFixed( 2 )
  
</script>

<!-- query -->
<?php
$conn = mysqli_connect("localhost","root","","employeesystem");

$checkid = "SELECT * FROM student WHERE studid = '$studid'";
$result = $conn->query($checkid);


/*query with rows*/
$checkid = "SELECT * FROM student WHERE studid = '$studid'";
$result = $conn->query($checkid);

if ($result->num_rows > 0) 
    while($row = $result->fetch_assoc()) 
        $stud = $row['studname'];
    


?>
<!-- for table row display -->
<table style="width:100%">
  <tr>
    <th>empid</th>
    <th>name</th> 
    <th colspan="3">combine</th>
  </tr>
  <?php while($row = mysqli_fetch_array($result)):?>
  <tr>
    <td><center><?php echo $row['studid'];?></center></td>
    <td><center><a href="viewstud.php?studid=<?php echo $row['studid'];?>">view</a></center></td>
  </tr>
  <?php endwhile;?>
</table>

【讨论】:

以上是关于如何在不提交和从数据列表中搜索的情况下从输入中获取价值的主要内容,如果未能解决你的问题,请参考以下文章

如何在不使用提交的情况下从下拉列表中选择值

如何让 GraphQL 在不进行轮询的情况下从数据库中获取实时/新数据?

如何在不阻塞的情况下从 Flux 获取列表?

如何在不刷新网页的情况下从下拉列表索引更改事件的数据库中检索数据

如何在不使用任何 ID 的情况下从 spotify API 获取艺术家列表

如何在不写入输出流的情况下从 ZipInputStream 获取每个 ZipFile 条目的字节/内容?