[英]How can I display value in textbox from database that value based on selected value from combobox in php?
I want to display value in textbox from database but the value based on selected value from combobox.我想在数据库的文本框中显示值,但该值基于 combobox 中的选定值。 Below are sample codes but I do know how to use value from database in array of jquery
以下是示例代码,但我知道如何在 jquery 数组中使用数据库中的值
<html>
<head>
</head>
<body>
<form id="taxDetails">
<select name="ItemCode" onchange="setTax(document.Form, this.value);">
<option value="">Select an Item from List...</option>
<option value="AB">Pen</option>
<option value="BC">Book</option>
<option value="ON">Note book</option>
</select>
<input name="showtax" type="text" id="showtax" value="<show-value-of-tax-here" />
</form>
<script>
var taxCodes = {
'AB': 5,
'BC': 12,
'ON': 13
};
var form = document.getElementById('taxDetails');
form.elements.ItemCode.onchange = function () {
var form = this.form;
form.elements.showtax.value = taxCodes[this.value];
};
</script>
</body>
</html>
Below is my query I want to use以下是我要使用的查询
$q= mysqli_query($connect,"select ItemCode, UnitPrice from oitm");
I do know how I can use the value from database in the following codes我确实知道如何在以下代码中使用数据库中的值
<script>
var taxCodes = {
'AB': 5,
'BC': 12,
'ON': 13
};
What I want is to select ItemCode and then display UnitPrice in textbox from above query我想要的是 select ItemCode 然后从上面的查询中在文本框中显示 UnitPrice
Please anyone can help me请任何人都可以帮助我
Use the form and submit a GET HTTP request to a PHP file (your file in this situation) which will fetch the data from the database, use the action attribute in the form tag like so:使用表单并将 GET HTTP 请求提交到 PHP 文件(在这种情况下是您的文件),该文件将从数据库中获取数据,使用表单标签中的 action 属性,如下所示:
<form method="get" action="your_file.php">
in the top of your file you can do this:在文件的顶部,您可以这样做:
$itemCode = $_GET['itemCode'];
$query = mysqli_query($connect,"select ItemCode, UnitPrice from oitm where ItemCode = '$itemCode");
$row = myqsli_fetch_array($query);
$price = $row['UnitPrice'];
And change the input value attribute to this:并将输入值属性更改为:
<input name="showtax" type="text" id="showtax" value="<?php echo if(isset($price)) echo $price ?>" />
Another solution is to use AJAX, you can use jquery to make a simple ajax request.另一种解决方案是使用 AJAX,您可以使用 jquery 发出简单的 ajax 请求。 hope this helps you.
希望这可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.