Jump to content

Dymnamic drop down list


snh

Recommended Posts

I have two drop down boxes in a form which are populated through MySQL, the second boxes options are dependant on the selection of the first box.  I am using a jump menu to populate the second drop down menu.  My problem is that when the second drop down menu is selected the form refreshes (because of the jump menu) and all of my previous data is deleted.  I am wanting to know how I can avoid my information being deleted.  Any suggestions would be great!

 

My code looks like this for my jump menu:

 

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+"Pratt_Instance_1.php?mcate="+selObj.options[selObj.selectedIndex].value+"&mind="+selObj.selectedIndex+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu2(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+"Pratt_Instance_1.php?mcate="+selObj.options[selObj.selectedIndex].value+"&mind="+selObj.selectedIndex+"$cate="+selObj.options[selObj.selectedIndex].value+"&ind="+selObj.selectedIndex);
  if (restore) selObj.selectedIndex=0;
}

//-->
</script>

 

The code for my drop down box is the following:

 

<select id="Instance_Type111" name="mcate" onchange="MM_jumpMenu('parent',this,0)">
			<option value="0">Select</option>
<?php

				// Get the Categories from Database
			if (!isset($type_array)){
			 $type_array=get_category_name();

			$query = "SELECT Type_ID, Type_Name FROM Instance_Type111";
				$query_result=@mysql_query($query,$mysql_link)
						or die ('Could not get categories! <br>\n');
				$type_array = db_result_to_array($query_result);
				}

		// Display Categories in the menu listing
		   $mi=1;
			foreach ($type_array as $row){
			$Type_ID= (string) $row['Type_ID'];
			$Type_Name= $row['Type_Name'];
			if ($mi!=$mind){
			print ("<option value=$Type_ID>$Type_Name</option>");
			} else {
			print ("<option value=$Type_ID selected>$Type_Name</option>");
			}
                 $mi++;
			}

			// Setting the main category code
	// $mcate_code is the maincat_id of main category chosen
		if(!isset($HTTP_GET_VARS['mcate']))	{
		  $mcade_code = 0;
		 } else{
		  $mcade_code =  $HTTP_GET_VARS['mcate'];
		}
?></select></td>

      			</tr>
      			
      			
		<tr>
<td >
Detailed Incident Type:
td>

<td>
<select name="cate" id="Detailed_Instance_LUT111" onChange="MM_jumpMenu2('parent',this,0)">
<option value="0"  >Select</option>

<?php
// Get the Categories from Database
//Get Detailed Definition from Database
$type_array=get_categories($mcade_code);
// Display Categories in the menu listing
display_category($type_array);
// Setting the main category code
	// $cate_code is the maincat_id of main category chosen
		if(!isset($HTTP_GET_VARS['cate']))	{
		  $icade_code = 0;
		 } else{
		  $icade_code =  $HTTP_GET_VARS['cate'];
		}

?></select></td>

 

Thanks!

 

 

Link to comment
https://forums.phpfreaks.com/topic/103456-dymnamic-drop-down-list/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.