我有以下代码:
$sql="SELECT * from customer_billing where sequence = '".$_GET["seq"]."' ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$result=mysql_fetch_array($rs);
?>
<script type="text/javascript">
function producttype(data) {
document.getElementById ("producttype").value = data.value;
}
function sagenominalcode(data) {
document.getElementById ("sagenominalcode").value = data.value;
}
</script>
<form method="post" action="editbillingline.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="50%"><strong>Product Type: </strong>
<br />
<select name="producttype-dropdown" id="producttype-dropdown" onchange="producttype(this)">
<option value="">none</option>
<?php
$sql2="SELECT * from customer_billing group by producttype order by producttype ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
$display='';
while($result2=mysql_fetch_array($rs2))
{
$display.='<option value="'.$result2["producttype"].'"';
if($result["producttype"]==$result2["producttype"]){$display.=' selected="selected" ';}
$display.='>'.$result2["producttype"].'</option>';
}
echo($display);
$display='';
?>
</select>
<input name="producttype" id="producttype" type="text" size="30" value="<?php echo $result["producttype"]; ?>" /></td>
因此它从工作正常的数据库中进行选择,然后当您更改下拉框中的选项时,它需要将值放入其下方的文本框中。如您所见,组合框是从 mysql 数据库生成的。
关于如何将所选项目的值插入文本框中的任何想法?
编辑:
<script type="text/javascript">
function producttype(data) {
document.getElementById ("producttype").value = data.value;
}
function sagenominalcode(data) {
document.getElementById ("sagenominalcode").value = data.value;
}
</script>
<form method="post" action="editbillingline.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="50%"><strong>Product Type: </strong>
<br />
<select name="producttype-dropdown" id="producttype-dropdown" onchange="producttype(this)">
<option value="">none</option>
<option value="PC Maintenance">PC Maintenance</option><option value="VoIP Telephony" selected="selected" >VoIP Telephony</option> </select>
<input name="producttype" id="producttype" type="text" size="30" value="VoIP Telephony" /></td>