如何获取选定的组合框值并以 html 形式加载其相应的数据
How to get selected combobox value and load its corresponding data in html form
我有从数据库加载值的组合框。我希望当用户从组合框中选择值时,表单应将数据库中的相应值加载到 html 表单中。这是我正在尝试的代码:
<div class="col-lg-6" style="display:none" id="c" >
<form id="aa" action="" method="post" >
<br><br><br>
<select name="id" id="id" class="span2" style=" width:150px;" onChange="this.form.submit();">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "valet";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$arr = array();
$sql = "SELECT id FROM tbl_user ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
?>
<option value="">-select user-</option>
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$arr[] = $row;
}
foreach($arr as $key => $row){
echo "<option value='".$row["id"]."'>".$row["id"]."</option>";
$GLOBALS['a'] = $row["first_name"];
$GLOBALS['b'] = $row["last_name"];
$GLOBALS['c'] = $row["phone"];
$GLOBALS['d'] = $row["company_id"];
$GLOBALS['e'] = $row["register_on"];
}
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
header('Location: webservices.php');
}
mysqli_close($conn);
?>
</select>
<br><br><br>
<input type="text" id="first_name" value="<?php $GLOBALS['a'] ?>" name="first_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="First Name*">
<br><br><br><br>
<input type="text" id="last_name" value="<?php $GLOBALS['b'] ?>" name="last_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Last Name*">
<br><br><br><br>
<input type="text" id="phone" value="<?php $GLOBALS['c'] ?>" name="phone" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Phone*">
<br><br><br><br>
<input type="text" id="company_id" value="<?php $GLOBALS['d'] ?>" name="company_id" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Company ID*">
<br><br><br><br>
<input type="text" id="register_on" value="<?php $GLOBALS['e'] ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Register On*">
<br><br><br><br>
<button name="edituser" id="edituser" type="submit" style="border:0;width:100px;margin-left: 45px;" >
<img src="images/save.png" alt="">
</button>
<button type="submit" style="border:0;width:100px;margin-left: 75px;">
<img src="images/cancel.png" alt="">
</button>
</form>
</div>
请帮我如何完成这项任务?
您可以使用 JQuery 来执行此操作。为了记录在案,Marco Mura
确实为您提供了解决问题的方法。你只是不想研究问题并在解决方案给你后解决问题。
$("#id").change(function(){
$.post("www.example.com?val=" + $(this).val(),function(response){
$("#mydiv").html(response);
})
})
相关文章:
- Webpack:如何将原始HTML加载为React JSX
- 画布 HTML 加载时间
- 使用 Ajax 在 html 加载后调用 jquery 插件
- 用javascript(不带外部文件)将html加载到另一个html中
- 错误 404 时,通过 jQuery 将 HTML 加载到 DIV 中
- 如何在将 html 加载到对话框中后更改标签的文本
- 如何将数据从服务器呈现的 html 加载到模型中
- jQuery 从外部 html 加载内容
- Ajax 将 html 加载到页面上并使用页面 js 不起作用
- 如何在没有安全警告的情况下将一个 html 加载到另一个 html 中
- 安卓:根据上一次活动列表中的选择,修改本地静态html加载的JS
- 在AppStore发布时,iOS应用程序上的index.html加载路径不正确
- 使jquery.load在HTML加载之前发生
- 使用jqueryload方法将ajax响应数据作为内部html加载到页面元素中
- HTML加载用户单击按钮时输入的输入字段数
- jQuery Mobile从新html加载第二个页面
- 使用ajax将html加载到Datatable子行中
- 使用JavaScript将HTML加载到DIV
- 使用JS和JQuery替换AJAX中的字符串或html加载
- js函数加载的页面无法使用js函数js-html加载另一个页面