我想在数据库中的文本框中显示值,但该值基于从组合框中选择的值。下面是示例代码,但我知道如何在 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>
以下是我要使用的查询
$q= mysqli_query($connect,"select ItemCode, UnitPrice from oitm");
我知道如何在以下代码中使用数据库中的值
<script>
var taxCodes = {
'AB': 5,
'BC': 12,
'ON': 13
};
我想要的是从上面的查询中选择 ItemCode,然后在文本框中显示 UnitPrice
请任何人都可以帮助我
使用表单并向 PHP 文件(在这种情况下是您的文件)提交一个 GET HTTP 请求,该文件将从数据库中获取数据,使用表单标签中的 action 属性,如下所示:
<form method="get" action="your_file.php">
在文件顶部,您可以执行以下操作:
$itemCode = $_GET['itemCode'];
$query = mysqli_query($connect,"select ItemCode, UnitPrice from oitm where ItemCode = '$itemCode");
$row = myqsli_fetch_array($query);
$price = $row['UnitPrice'];
并将输入值属性更改为:
<input name="showtax" type="text" id="showtax" value="<?php echo if(isset($price)) echo $price ?>" />
另一种解决方案是使用AJAX,您可以使用jquery 进行简单的ajax 请求。希望这对你有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句