drop down populate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisles
    New Member
    • Jan 2010
    • 40

    drop down populate

    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:

    Code:
    //gazetted or non gazetted
    $isGazetted = array(
    	"1" => "Yes",
    	"2" => "No"
    );
    
    //Gazetted
    $gazTypey = array(
    	"1" => "Notifications",
    	"2" => "Orders"
    );
    
    //non Gazetted
    $gazTypen = array(
    	"1" => "Elections",
    	"2" => "Others"
    );
    my code to populate the drop downs is written below:
    Code:
    function getGazette(){
    	global $isGazetted;
    	$output = '<select name="cmbType" id="cmbType">';
    	$output .= '<option value="">select value</option>';	
    	foreach($isGazetted as $k=> $v){
    		if($_POST['cmbType'] == $k){
    			$output .= '<option value="'.$k.'" selected>'.$v.'</option>';
    		}else{
    			$output .= '<option value="'.$k.'">'.$v.'</option>';		
    		}
    	}
    	$output .= '</select>';
    	return $output;
    }
    function getGazType($Type){
    	global $gazTypey,$gazTypen;
      
    	if($Type == 1){
    	$output = '<select name="cmbTypey" id="cmbTypen">';
    	$output .= '<option value="">select value</option>';	
    	foreach($gazTypey as $k=> $v){
    		if($_POST['cmbTypey'] == $k){
    			$output .= '<option value="'.$k.'" selected>'.$v.'</option>';
    		}else{
    			$output .= '<option value="'.$k.'">'.$v.'</option>';		
    		}
    	}
    	
    	$output .= '</select>';
    	return $output;
    	}
    
    	else 
    	{
    	$output = '<select name="cmbTypen" id="cmbTypen">';
    	$output .= '<option value="">select value</option>';	
    	foreach($gazTypen as $k=> $v){
    		if($_POST['cmbTypen'] == $k){
    			$output .= '<option value="'.$k.'" selected>'.$v.'</option>';
    		}else{
    			$output .= '<option value="'.$k.'">'.$v.'</option>';		
    		}
    	}
    	
    	$output .= '</select>';
    	return $output;
    	}
    }
    ?>
    <?php include_once "admin_templates/case_header.php"; ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/jscal2.css" />
      <link type="text/css" rel="stylesheet" href="../inc/jscalender/css/border-radius.css" />
      <link id="skin-win2k" title="Win 2K" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/win2k/win2k.css" />
      <link id="skinhelper-compact" type="text/css" rel="alternate stylesheet" href="../inc/jscalender/css/reduce-spacing.css" />
      <script src="../inc/jscalender/js/jscal2.js"></script>
      <script src="../inc/jscalender/js/lang/en.js"></script>
    </head>
    
    <body>
    <form name="frmSubmit" id="frmSubmit" action="" method="POST" enctype="multipart/form-data" >
    <fieldset style="width:20px">
    <legend ><b> Search File</b></legend>
      <table width="150" border="1">
      <tr>
          <td height="31">Gazetted:</td>
    	  <td><?=getGazette()?></td>
      </tr>
      <tr>
      <td>Subject: </td>
          <td> 
            <?=getGazType($_POST['cmbType'])?>
          </td>
      </tr>
      <tr>
          <td>Keyword:</td>
      <td><input name="txtKey" type="text" id="txtKey"></td>
      </tr>
      <tr>
          <td>Date:</td>
      <td><input id="srcDOF" readonly name="srcDOF" type="text">
      <img src="http://bytes.com/submit/images/cal.gif" id="srcDOFImg">
                         
    			<script type="text/javascript">
              new Calendar({
                      inputField: "srcDOF",
                      dateFormat: "%d-%m-%Y",
                      trigger: "srcDOFImg",
                      bottomBar: true,
                      //max:  Calendar.dateToInt(new Date()),
                      onSelect: function() {
                              var date = Calendar.intToDate(this.selection.get());
                              this.hide();
                      }
              });
            </script>
    		</td>
      </tr>
      <tr>
      <td></td>
     <td>
        	<input type="file" name="txtFile" id="txtFile"  />
        </td>
      </tr>
    </table>
    <input name="search" type="submit" value="Search"/>
      <input name="cancel" value="Cancel" type="reset">
      </fieldset>
    </form>
    
    </body>
    </html>
    bt the drop down is nt populatin properly.only the non gazetted values are shown.pz help
    Last edited by Atli; Jan 27 '10, 01:37 PM. Reason: Added [code] tags.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    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

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      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.

      Comment

      • lisles
        New Member
        • Jan 2010
        • 40

        #4
        thanx every1:)....i'l try to figure it out

        Comment

        • dgreenhouse
          Recognized Expert Contributor
          • May 2008
          • 250

          #5
          Here's a conceptual design view that might help your thinking.
          Hover over the partial image shown to get a full view.

          Comment

          Working...