我构建了一个查询,该查询返回我需要的值并将它们放入下拉列表中。当我在下拉列表中选择一个项目时,我将选项的值放入表单字段中。
现在,我还想将数组中的第二个值放入不同的表单字段中。 (例如,第一个字段包含订单号,第二个字段包含客户名称,依此类推。我可以将明文放入第二个字段中,但无法$row[field_value]
数组值工作。
如果我可以在将项目选择到单独的 php 文件以运行完整查询并将结果返回到 tom 字段时使用该值运行触发器,它将起作用。
.PHP:
$query5 = "SELECT customers.id, customers.email, customers_customfields.customer_id, customers_customfields.field_value, orders.sign_date,orders.sub_id, orders.domain_name, orders.cust_status
FROM customers, customers_customfields, customers_orders, orders
WHERE customers_orders.order_id = orders.sub_id
AND customers.id = customers_orders.customer_id
AND customers.id = customers_customfields.customer_id
AND customers_customfields.field_id = 1";
$result5 = mysql_query($query5) or die("Unable to query CPU parts");
$option = "";
while($row=mysql_fetch_array($result5)) {
$option .= "<option value='{$row[sub_id]}'>{$row[sub_id]} {$row[cust_status]} {$row[sign_date]} {$row[field_value]};</option>";
}
// close connection
mysql_close($server);
?>
.HTML:
<!-- // ====================================================Select and input Order Number Code =========== -->
<form name="Submit" onsubmit="CheckForm()">
<select name="Orders" onchange="document.Submit.showValue1.value=this.value; document.Submit.showValue2.value=['Array Value']">
// <? echo $option; ?>
</select>
<input type="text" name="showValue1"><br>
<input type="text" name="showValue2" ><br>
您可以
尝试将data-your_value="$row['your_value']"
添加到每个选项,然后尝试使用类似 this.options[this.selectedIndex].attributes['data-your_value'].value
的代码检索此值。
下面是一个示例:http://jsfiddle.net/UVKY8/1/。
我建议您更改此行
$option .= "<option value='{$row[sub_id]}'>{$row[sub_id]} {$row[cust_status]} {$row[sign_date]} {$row[field_value]};</option>";
进入这个
$option .= "<option value='" . $row['sub_id'] . "'>" . $row['sub_id']. " " . $row['cust_status'] . " " . $row['sign_date'] ." " . $row['field_value'] .";</option>";