在CCS Example2 上的範例:
order.php 網頁上一個欄位: customer、是一個選單欄位
下拉式 Selection,變更(onchange())就去資料庫讀取 客戶姓名、地址等客戶資料。
設計如下:
1. 在 customer欄位裡面
<select id="orders1order_customer_id" onchange="OpenCustomerInfo(this.value);" name="{order_customer_id_Name}">
<option value="" selected>Select Value</option>
{order_customer_id_Options}
</select>
2. 在head 裡面建立:
<script language="JavaScript" type="text/javascript">
function OpenCustomerInfo(cust_id) {
var win = window.open("GetCustomerInfo.php?customer_id="+cust_id,"CustomerInfo","height=1,width=1,toolbar=no,scrollbars=no,menubar=no");
win.focus();
}
</script>
3. 另外,用CCS寫一個 GetCustomerInfo.php 程式
<!DOCTYPE HTML>
<html>
<head>
<title>Please Wait...</title>
<script language="JavaScript" type="text/javascript">
function getCustomerInfo(){
<!-- BEGIN Record Customer -->
window.opener.document.orders1.order_ship_address.value = "{customer_address}";
window.opener.document.orders1.order_ship_city.value = "{customer_city}";
window.opener.document.orders1.order_ship_state.value = "{customer_state}";
window.opener.document.orders1.order_ship_zip.value = "{customer_zip}";
<!-- END Record Customer -->
window.opener.focus();
window.close();
}
</script>
</head>
<body onload="getCustomerInfo();">
Please Wait
</body>
</html>