我有一个带有选择字段和输入字段的表单:
select字段从customer表的customer_name列获取所有客户名称,并允许用户选择客户名称。选择客户名称后,将使用该名称并将其显示在“添加客户名称”输入中,并获取客户电话号码(来自客户表中的phone_num列)并将其显示在“客户电话”中输入。
我正在使用My_SQL和PHP来执行此操作。
到目前为止,我可以在“客户”选择字段中正确显示客户名称。但是,该名称不会出现在“添加客户名称”输入中,也不会在“客户电话”输入中显示客户的电话号码。
有没有人知道如何使用PHP,JavaScript或两者兼而有之?
以下是此网络表单部分的代码:
<script type="text/javascript">
$(document).ready(function () {
$("#customer").change(function() {
if($( "#customer option:selected" ).text() == 'Add a Customer') {
$( "#customer_name" ).show();
$( "#cusphone" ).show();
$( "#cusphone1" ).show();
$( "#customer_name1" ).show();
} else {
$( "#customer_name" ).hide();
$( "#cusphone" ).hide();
$( "#cusphone1" ).hide();
$( "#customer_name1" ).hide();
}
});
});
</script>
<form id="form1" name="form1" method="post" action="add_invoice.php" enctype="multipart/form-data" class="form-horizontal" role="form">
<div class="form-group">
<label for="travel_task" class="col-sm-4 control-label">Customer<span class="brand-color"></span>:</label>
<div class="col-sm-8">
<select id="customer" name="customer" required class="chosen-select-deselect form-control" width="380">
<option value=''></option>
<?php
$result = mysqli_query($dbc, "SELECT distinct(customer_name) FROM customer");
while($row = mysqli_fetch_assoc($result)) {
if ($customer_name == $row['customer_name']) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option ".$selected." value = '".$row['customer_name']."'>".$row['customer_name']."</option>";
}
?>
<option value = 'Other'>Add a Customer</option>
</select>
</div>
</div>
<div class="form-group">
<label for="travel_task" id="customer_name" style="display: none;" class="col-sm-4 control-label">Add Customer Name:</label>
<div class="col-sm-8">
<input name="customer_name" id="customer_name1" type="text" class="form-control" style="display: none;"/>
</div>
</div>
<div class="form-group">
<label for="site_name" id="cusphone1" style="display: none;" class="col-sm-4 control-label">Customer Phone:</label>
<div class="col-sm-8">
<input name="cusphone" id="cusphone" type="text" class="form-control" style="display: none;"/>
</div>
</div>
感谢您的帮助。非常感谢所有帮助。