PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 14th, 2004, 09:36 PM
aaronchu aaronchu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 aaronchu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;


Reply With Quote
  #2  
Old August 20th, 2004, 03:26 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,029 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2966446 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 1 Week 12 h 55 m 59 sec
Reputation Power: 15
Send a message via ICQ to Itsacon
Javascript can't call PHP functions, nor MySQL queries. If you want the dropdowns to change without resubmitting the page, you'll need to include all the data in advance (possibly in a hardcoded javascript array), and set the somethingselected function to read from this array.

You can have PHP generate the javascript array during runtime, but once the page is loaded, you're stuck with the data you have.

Hope this helps

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Drop Down Menu


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap