我想用所有与下拉框中选择的名称对应的数据填充所有文本框。我已经搜索了它的代码,但不幸的是它都没有用。
PHP
<?php
include("webconfig.php");
session_start();
?>
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="img/logo_trans.png">
<link rel="stylesheet" href="css/iconFont.css">
<link rel="stylesheet" href="css/metro-bootstrap.css">
<link rel="stylesheet" href="css/metro-bootstrap-responsive.css">
<script src="js/jquery/jquery.min.js"></script>
<script src="js/jquery/jquery.widget.min.js"></script>
<script src="js/load-metro.js"></script>
<!-- Local JavaScript -->
<script src="js/docs.js"></script>
<script src="js/github.info.js"></script>
<script src="js/Chart.js"></script>
<script src="js/metro-dropdown.js"></script>
<title>AS_SIGNS</title>
</head>
<body class="metro">
<nav class="horizontal-menu" style="background:#037E04;">
<ul>
<center><li><a href="index.php"><h1><font color="#FFFFFF">AS Signs</font></h1></a></li></center>
</ul>
</nav>
<div style="width:70%; height:60%; position:absolute; left:0;">
<div style="width:100%; height:100%;overflow:scroll; overflow-x:hidden; overflow-y:auto;">
<div style="width:50%; float:left;">
<h2>New Service Call</h2>
<form method="post" name="form">
<table class="table bordered" width="100%">
<tr>
<td>Customer ID</td>
<td><input type="text" name="custid" /></td>
</tr>
<tr>
<td>Customer Name</td>
<td>
<select name="CUSTOMER_NAME" style="width:205px" required>
<option value="default"></option>
<?php
$sql1 = "SELECT * FROM CUSTOMER_MASTER";
$sth = ibase_query($conn, $sql1) or die(ibase_errmsg());
$num = '';
while($row = ibase_fetch_assoc($sth))
{
$name = $row["ACCOUNT_NAME"];
echo "<option value=\"$name\">$name</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="ADDRESS" value="<?php echo "$add"?>"></td>
</tr>
</table>
</div>
<div style="width:50%; float:right;">
<h2 style="visibility:hidden;">cqcqcqcqc</h2>
<table class="table bordered" width="100%">
<tr>
<td>Contact Person</td>
<td><input type="text" name="CONTACT_PERSON" value="<?php echo "$contperson"?>"></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input type="text" name="CONTACT_NUMBER" value= "<?php echo "$contnum"?>"> </td>
</tr>
</table>
<input type="submit" name="btnSave" value="SAVE" />
<input type="button" name="load" value="LOAD" />
<?php
if(isset($_POST['load']))
{
$sql = "SELECT * FROM CUSTOMER_MASTER WHERE CUSTOMER_NAME = '$name'";
$result = ibase_query($query, $conn);
$details = ibase_fetch_assoc($result);
$sth = ibase_query($conn, $sql) or die(ibase_errmsg());
$add = $details["ADDRESS"];
$name = $_POST["ACCOUNT_NAME"];
$servicenum = $details["SERVICE_CALL_NUMBER"];
$contperson = $details["CONTACT_PERSON"];
$contnum = $details["CONTACT_NUMBER"];
}
?>
<?php
$sql = "SELECT * FROM SERVICE_REPORTS";
$sth = ibase_query($conn, $sql) or die(ibase_errmsg());
$add = $_POST["ADDRESS"];
$name = $_POST["CUSTOMER_NAME"];
$servicenum = $_POST["SERVICE_CALL_NUMBER"];
$contperson = $_POST["CONTACT_PERSON"];
$contnum = $_POST["CONTACT_NUMBER"];
if(isset($_POST['btnSave']))
{
ibase_query($conn, "INSERT INTO SERVICE_REPORTS (CUSTOMER_NAME, ADDRESS, CONTACT_PERSON, CONTACT_NUMBER) VALUES('$name', '$add', '$contperson', '$contnum')") or die (ibase_errmsg());
echo "Record Saved";
}
?>
</form>
</div>
</div>
</div>
<div class="span5" style="position: absolute;right:0; top:100px;">
<nav class="sidebar dark">
<ul>
<li class="active"><a href="#"><i class="icon-home"></i>Home</a></li>
<li class="stick bg-red">
<a class="dropdown-toggle" href="#"><i class=""></i>Service Call</a>
<ul class="dropdown-menu" data-role="dropdown" data-effect="slide">
<li><a href="servicecallnew.php">New Service</a></li>
<li><a href="#">Service Call List</a></li>
</ul>
</li>
<li class="stick bg-red">
<a class="dropdown-toggle" href="#"><i class="icon-sale"></i>File Maintenance</a>
<ul class="dropdown-menu" data-role="dropdown" data-effect="slide">
<li><a href="items.php?itd=&action">Items</a></li>
<li><a href="categories.php">Categories</a></li>
<li><a href="contractors.php">Contractors</a></li>
<li><a href="suppliers.php">Suppliers</a></li>
</ul>
</li>
<li class="stick bg-red">
<a class="dropdown-toggle" href="#"><i class="icon-box-add"></i>Production</a>
<ul class="dropdown-menu" data-role="dropdown">
<li><a href="estimatelist.php">Estimate / Quotation</a></li>
<li><a href="bomlist.php">Bill of Materials</a></li>
<li><a href="bomposting.php">BOM Posting</a></li>
<li><a href="issuancelist.php">Issuance</a></li>
<li><a href="adjplist.php">Adjustment</a></li>
</ul>
</li>
<li class="stick bg-red">
<a class="dropdown-toggle" href="#"><i class="icon-box-add"></i>Inventory</a>
<ul class="dropdown-menu" data-role="dropdown">
<li><a href="receiving.php">Receiving</a></li>
</ul>
</li>
<li class="stick bg-red">
<a class="dropdown-toggle" href="#"><i class="icon-printer"></i>Reports</a>
<ul class="dropdown-menu" data-role="dropdown">
<!-- <li><a onClick="<?php echo "window.open('report_prod.php?type=estimate','mywindow3')"; ?>">Estimate / Quotation</a></li>
<li><a onClick="<?php echo "window.open('report_prod.php?type=bom','mywindow3')"; ?>">Bill of Materials</a></li>
<li><a onClick="<?php echo "window.open('report_prod.php?type=issuance','mywindow3')"; ?>">Issuance</a></li>
<li><a onClick="<?php echo "window.open('report_prod.php?type=adj','mywindow3')"; ?>">Adjustment</a></li>
<li><a onClick="<?php echo "window.open('rptinventory.php?','mywindow8','menubar=0,location=1,status=1,scrollbars=1,width=1000,height=500,left=0,top=0,screenX=50,screenY=100')"; ?>">Inventory</a></li>-->
<li><a href="signspec.php">Sign Spec</a></li>
<li><a href="warehouse.php">Warehouse</a></li>
</ul>
</li>
<li class="stick bg-red"><a href="#"><i class="icon-cog"></i>Settings</a></li>
<li class="stick bg-red"><a href="logout.php"><i class="icon-switch"></i>Logout</a></li>
</ul>
</nav>
</div>
</body>
</html>
答案 0 :(得分:0)
我会给你一些提示。
1)将您的查询置于doctype之上,而不是在页面中间。
2)在选择菜单中使用onchange属性来执行预先计算数据的javascript函数。
3)使用json_encode()
将查询结果转换为json字符串,然后将该字符串分配给javscript变量,该函数可用于填充字段。
答案 1 :(得分:0)
如果我理解正确,你需要javascript来为你做这件事。您需要做的是触发一个事件,当选择发生更改时,该事件会更改文本输入值。例如,对于客户名称,您可以这样做:
$("#customer-name-select").change(function(){
var customerName = $("option:selected").text();
$("#customer-name-select").val(customerName);
});