
August 14th, 2004, 09:36 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Drop Down Menu
I have been trying to populate a drop down menu using data downloading dynamic from SQL server. Since PHP is not able to populate data without submitting the form, so I try to do it in Javascript as follows: ( My goal is Select data based on the first 2 drop down menu, and display the order list in 3rd menu)
HELP is greatly appreciated
**** HERE IS START
PHP Code:
<?php require_once('db_fns.php'); ?> <html> <head> <SCRIPT LANGUAGE="JavaScript"><!-- function somethingselected(oList){ var curform = oList.form; // get the containing form clearCombo(curform.orderlist); // clear the downstream list var newvalue1 = document.orderform.duration.options[document.orderform.duration.selectedIndex].value; var newvalue2 = document.orderform.cliniccode.options[document.orderform.cliniccode.selectedIndex].value; var nArray = get_db_orderlist(newvalue1, newvalue2); // <=Getting Error something like "Saying need a object?!" (in Chinese) // <= PLAN TO ADD the drop down menu via nArray (Not yet done!) } function clearCombo(oList){ for (var i = oList.options.length - 1; i >= 0; i--){ oList.options[i] = null; } oList.selectedIndex = -1; } function fillCombo(oList, vValue){ if (vValue != "" && assocArray[vValue]){ var arrX = assocArray[vValue]; for (var i = 0; i < arrX.length; i = i + 2){ oList.options[oList.options.length] = new Option(arrX[i + 1], arrX[i]); } } else oList.options[0] = new Option("None found", ""); } </SCRIPT> <title>Material/Drug Order Form</title> </head> <body> <FORM name="orderform"> <table width=100% border=0 cellspacing = 0 bgcolor=#FFFFFF> <tr> <td bgColor=#e2eefa width="30%"><Font color=#000000 face=Arial><SPAN style="FONT-SIZE: 12pt" style="font-weight: bold">View Order Form 檢視訂貨表: <select name="duration" onchange="somethingselected(this);"><option value=3>3個月內</option><option value=6>6個月內</option><option value=12>1年內</option><option value=24>2年內</option></select> <select name="cliniccode" onchange="somethingselected(this);"><option value="CTL">Central</option><option value="CWB">Causeway Bay</option><option value="DB">Discovery Bay</option><option value="DH1">Diamond Hill</option> <option value="HEAD">Head Office</option><option value="HFC">Heng Fa Chuen</option><option value="KIG">Kingwood Ginza</option><option value="LT1">Lam Tin</option><option value="MK1">Mongkok</option> <option value="MOS">Ma On Shan</option><option value="PU0">PolyTechnic University</option><option value="ST">Shatin</option><option value="TKO">Tseung Kwan O</option><option value="TM1">Tuen Mun</option> <option value="TP1">Tai Po Plaza</option><option value="TPF">Tai Po Fortune</option><option value="TW1">Tsuen Wan</option><option value="YL1">Yuen Long</option></select> <select name="orderlist" onchange="getorderdetail();"><option value="none">Please select clinic</option></select> </td> </tr> </table>
PHP Code:
// included by dn_fns.php function get_db_orderlist($order_date, $cliniccode) { // query database for a list of categories $conn = db_connect(); $query = "select order_date, cliniccode from order_form where order_date='".$order_date."' and cliniccode LIKE '".$cliniccode."'"; $result = @mssql_query($query); if (!$result) return false; $num_cats = @mssql_num_rows($result); if ($num_cats ==0) return false; $result = db_result_to_array($result); return $result; }
|