[英]Passing a value from html select field to mysql query using java script/ajax in same page with out refreshing the page
I have the following select field, values are populating from mysql table. 我有以下选择字段,值从mysql表填充。 The dropdown contains around 8-10 values.
下拉列表包含约8-10个值。
<select id ="name" name="name" class="form" required>
<option value="" disabled selected>Name</option>
<?php
$sql = "select name from accounts where id = '{$_SESSION['SESS_MEMBER_ID']}'";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_array($result)) {
$name = ($row['name']);
echo '<option value=".$name.">' . $name . '</option>';
}
?>
</select>
How can I pass the selected value from the above dropdown list to the below sql query(to where condition)? 我怎样才能从上面的下拉列表中选择的值传递到下面的SQL查询(到哪里条件)? And also I need to populate the output of the below query to the below two input fields.
我还需要将以下查询的输出填充到以下两个输入字段。 Both the above select field and below input fields are in same page.
上面的选择字段和下面的输入字段都在同一页面中。
<?php
$sql = "select income,expense from accounts where name = '' and id = '{$_SESSION['SESS_MEMBER_ID']}'";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
if (mysqli_num_rows($result) > 0)
while ($row = mysqli_fetch_array($result)) {
$inc = $row['income'];
$exp = $row['expense'];
?>
<div class="col-md-3">
<input value="<?php echo $inc ?>" class="form" readonly/>
</div>
<div class="col-md-3 ">
<input value="<?php echo $exp ?>" class="form" readonly/>
</div>
Thanks in advance for suggessions and advice. 在此先感谢您的建议和建议。
Using Jquery you can do an on change function: 使用Jquery,您可以执行on change函数:
$('#name').change(function (e) {
var parameter = $(this).val();
Pass Parameter to your query and return values
$('#input1ID').val($row['income']);
$('#input2ID').val($row['expense']);
})
Sorry I don't know PHP or how to start the function, but this will pass a value to the query everytime you change the dropdown. 抱歉,我不知道PHP或如何启动该函数,但是每次您更改下拉列表时,这都会将值传递给查询。 This will not refresh the page.
这不会刷新页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.