473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

drop down populate

40
i want to populate a drop down based on a selection from anoher drop down list.
my drop down values are stored in a seperate page as shown below:

Expand|Select|Wrap|Line Numbers
  1. //gazetted or non gazetted
  2. $isGazetted = array(
  3.     "1" => "Yes",
  4.     "2" => "No"
  5. );
  6.  
  7. //Gazetted
  8. $gazTypey = array(
  9.     "1" => "Notifications",
  10.     "2" => "Orders"
  11. );
  12.  
  13. //non Gazetted
  14. $gazTypen = array(
  15.     "1" => "Elections",
  16.     "2" => "Others"
  17. );
  18.  
my code to populate the drop downs is written below:
Expand|Select|Wrap|Line Numbers
  1. function getGazette(){
  2.     global $isGazetted;
  3.     $output = '<select name="cmbType" id="cmbType">';
  4.     $output .= '<option value="">select value</option>';    
  5.     foreach($isGazetted as $k=> $v){
  6.         if($_POST['cmbType'] == $k){
  7.             $output .= '<option value="'.$k.'" selected>'.$v.'</option>';
  8.         }else{
  9.             $output .= '<option value="'.$k.'">'.$v.'</option>';        
  10.         }
  11.     }
  12.     $output .= '</select>';
  13.     return $output;
  14. }
  15. function getGazType($Type){
  16.     global $gazTypey,$gazTypen;
  17.  
  18.     if($Type == 1){
  19.     $output = '<select name="cmbTypey" id="cmbTypen">';
  20.     $output .= '<option value="">select value</option>';    
  21.     foreach($gazTypey as $k=> $v){
  22.         if($_POST['cmbTypey'] == $k){
  23.             $output .= '<option value="'.$k.'" selected>'.$v.'</option>';
  24.         }else{
  25.             $output .= '<option value="'.$k.'">'.$v.'</option>';        
  26.         }
  27.     }
  28.  
  29.     $output .= '</select>';
  30.     return $output;
  31.     }
  32.  
  33.     else 
  34.     {
  35.     $output = '<select name="cmbTypen" id="cmbTypen">';
  36.     $output .= '<option value="">select value</option>';    
  37.     foreach($gazTypen as $k=> $v){
  38.         if($_POST['cmbTypen'] == $k){
  39.             $output .= '<option value="'.$k.'" selected>'.$v.'</option>';
  40.         }else{
  41.             $output .= '<option value="'.$k.'">'.$v.'</option>';        
  42.         }
  43.     }
  44.  
  45.     $output .= '</select>';
  46.     return $output;
  47.     }
  48. }
  49. ?>
  50. <?php include_once "admin_templates/case_header.php"; ?>
  51. <html>
  52. <head>
  53. <title>Untitled Document</title>
  54. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  55.  <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/jscal2.css" />
  56.   <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/border-radius.css" />
  57.   <link id="skin-win2k" title="Win 2K" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/win2k/win2k.css" />
  58.   <link id="skinhelper-compact" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/reduce-spacing.css" />
  59.   <script src="../inc/jscalender/js/jscal2.js"></script>
  60.   <script src="../inc/jscalender/js/lang/en.js"></script>
  61. </head>
  62.  
  63. <body>
  64. <form name="frmSubmit" id="frmSubmit" action="" method="POST" enctype="multipart/form-data" >
  65. <fieldset style="width:20px">
  66. <legend ><b> Search File</b></legend>
  67.   <table width="150" border="1">
  68.   <tr>
  69.       <td height="31">Gazetted:</td>
  70.       <td><?=getGazette()?></td>
  71.   </tr>
  72.   <tr>
  73.   <td>Subject: </td>
  74.       <td> 
  75.         <?=getGazType($_POST['cmbType'])?>
  76.       </td>
  77.   </tr>
  78.   <tr>
  79.       <td>Keyword:</td>
  80.   <td><input name="txtKey" type="text" id="txtKey"></td>
  81.   </tr>
  82.   <tr>
  83.       <td>Date:</td>
  84.   <td><input id="srcDOF" readonly name="srcDOF" type="text">
  85.   <img src="http://bytes.com/submit/images/cal.gif" id="srcDOFImg">
  86.  
  87.             <script type="text/javascript">
  88.           new Calendar({
  89.                   inputField: "srcDOF",
  90.                   dateFormat: "%d-%m-%Y",
  91.                   trigger: "srcDOFImg",
  92.                   bottomBar: true,
  93.                   //max:  Calendar.dateToInt(new Date()),
  94.                   onSelect: function() {
  95.                           var date = Calendar.intToDate(this.selection.get());
  96.                           this.hide();
  97.                   }
  98.           });
  99.         </script>
  100.         </td>
  101.   </tr>
  102.   <tr>
  103.   <td></td>
  104.  <td>
  105.         <input type="file" name="txtFile" id="txtFile"  />
  106.     </td>
  107.   </tr>
  108. </table>
  109. <input name="search" type="submit" value="Search"/>
  110.   <input name="cancel" value="Cancel" type="reset">
  111.   </fieldset>
  112. </form>
  113.  
  114. </body>
  115. </html>
bt the drop down is nt populatin properly.only the non gazetted values are shown.pz help
Jan 27 '10 #1
4 2638
johny10151981
1,059 1GB
This is a huge program I got confused. Why dont you do this.

First try a simple dynamic dropdown list.

If you get any error then we will be able to help you. if you dont get any error it may be help you to understand how to create critical drop down lists :)

regards,
johny
Jan 27 '10 #2
kovik
1,044 Expert 1GB
I think they call this "dropdown chaining." Googling it should give some good results. This is typically done in JavaScript, however.

If you want to do it in PHP, it shouldn't be difficult at all. However, I'm not too keen on sorting through your code to find out exactly what you are trying to do.
Jan 27 '10 #3
lisles
40
thanx every1:)....i'l try to figure it out
Jan 29 '10 #4
dgreenhouse
250 Expert 100+
Here's a conceptual design view that might help your thinking.
Hover over the partial image shown to get a full view.

Jan 29 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
2
by: Phillip Parr | last post by:
Hello, I have this script which should populate a drop down box depending on another drop box. The error is somewhere in this code here, but I can't find it. Any help would be greatly appreciated!...
3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
1
by: csgraham74 | last post by:
Hi Guys, I am currently building a web aplication in ASP.Net. On the onload event of a page a have a function to populate the many drop down lists on my page. I have one parameter table which...
7
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
by: jsd219 | last post by:
Hello, hopefully someone can help me with this: I currently have a php file that pulls a query from the field "category" from my database. this file is called category.php. I am trying to populate...
8
by: dskanth | last post by:
I have 4 drop down lists, namely Location, country, State and City. Ex: Location: Asia, Country: India, State: Andhra Pradesh, City: Hyderabad. If i select any option in the Location drop down...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.