|  | 
	                
  
    | 
	 
        อ้างอิงจากโค้ด listbox 3 ชั้น คือผมต้องการให้ submit ไปที่อีกหน้าต่างนึง ซึ่งมี listbox ชุดเดิมอยู่ แต่ต้องการให้โชว์ค่าที่เลือกไว้จากหน้าแรก     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | สมมติเราเลือก ภาค จังหวัด อำเภอเรียบร้อยแล้วซับมิท ไปอีกหน้าต่างซึ่งต้องการให้โชว์ listbox ชุดเดิมแต่โชว์ค่าที่เลือกไว้จากหน้าที่แล้ว ต้องทำยังไงครับ 
 Code (PHP)
 
 <?php
	/*** By Weerachai Nukitram ***/
	/***  http://www.ThaiCreate.Com ***/
	$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
	$objDB = mysql_select_db("thailand");
	@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
		//**** List Province (Start) ***//
		function ListProvince(SelectValue)
		{
			frmMain.ddlProvince.length = 0
			frmMain.ddlAmphur.length = 0
			
			//*** Insert null Default Value ***//
			var myOption = new Option('','')  
			frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
			
			<?
			$intRows = 0;
			$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
			$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			$intRows = 0;
			while($objResult = mysql_fetch_array($objQuery))
			{
			$intRows++;
			?>			
				x = <?=$intRows;?>;
				mySubList = new Array();
				
				strGroup = <?=$objResult["GEO_ID"];?>;
				strValue = "<?=$objResult["PROVINCE_ID"];?>";
				strItem = "<?=$objResult["PROVINCE_NAME"];?>";
				mySubList[x,0] = strItem;
				mySubList[x,1] = strGroup;
				mySubList[x,2] = strValue;
				if (mySubList[x,1] == SelectValue){
					var myOption = new Option(mySubList[x,0], mySubList[x,2])  
					frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption					
				}
			<?
			}
			?>																	
		}
		//**** List Province (End) ***//
		
		//**** List Amphur (Start) ***//
		function ListAmphur(SelectValue)
		{
			frmMain.ddlAmphur.length = 0
			//*** Insert null Default Value ***//
			var myOption = new Option('','')  
			frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
			
			<?
			$intRows = 0;
			$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
			$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			$intRows = 0;
			while($objResult = mysql_fetch_array($objQuery))
			{
			$intRows++;
			?>
				x = <?=$intRows;?>;
				mySubList = new Array();
				
				strGroup = <?=$objResult["PROVINCE_ID"];?>;
				strValue = "<?=$objResult["AMPHUR_ID"];?>";
				strItem = "<?=$objResult["AMPHUR_NAME"];?>";
				mySubList[x,0] = strItem;
				mySubList[x,1] = strGroup;
				mySubList[x,2] = strValue;
							
				if (mySubList[x,1] == SelectValue){
					var myOption = new Option(mySubList[x,0], mySubList[x,2])  
					frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption					
				}
			<?
			}
			?>																	
		}
		//**** List Amphur (End) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
	Geography 
	<select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
	<option selected value=""></option>
	<?
	$strSQL = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	while($objResult = mysql_fetch_array($objQuery))
	{
	?>
	<option value="<?=$objResult["GEO_ID"];?>"><?=$objResult["GEO_NAME"];?></option>
	<?
	}
	?>
	</select>
	Province
	<select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)"></select>
	Amphur
	<select id="ddlAmphur" name="ddlAmphur" style="width:200px"></select>
</form>
</body>
</html>
<?
	mysql_close($objConnect);
?>
 
 
 Tag : PHP, MySQL, JavaScript
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2011-08-27 16:04:02 | By :
                          Pavich | View :
                          995 | Reply :
                          4 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | สงสัยคุณจะไม่ได้ดูเพิ่มเติมจากข้างล่างที่เขียนให้ 
 Code (PHP)
 
 <script language="JavaScript">
	function setDefault()
	{
		<?
			/*** ค่า Default ที่ได้จากการจัดเก็บ ***/
			$strGeography = "3";
			$strProvince = "20";
			$strAmphur= "252";
		?>
			<?
			/*** Default Geography  ***/
			if($strGeography != "")
			{
			?>
				var objGeo=document.frmMain.ddlGeo;
				for (x=0;x<objGeo.length;x++)
				{
					if (objGeo.options[x].value=="<?=$strGeography?>")
					{
						objGeo.options[x].selected = true;
						break;
					}
				}
				ListProvince(<?=$strGeography;?>)
			<?
			}
			?>
			<?
			/*** Default Province  ***/
			if($strProvince != "")
			{
			?>
				var objProvince=document.frmMain.ddlProvince;
				for (x=0;x<objProvince.length;x++)
				{
					if (objProvince.options[x].value=="<?=$strProvince?>")
					{
						objProvince.options[x].selected = true;
						break;
					}
				}
				ListAmphur(<?=$strProvince;?>)
			<?
			}
			?>
			<?
			/*** Default Amphur  ***/
			if($strAmphur != "")
			{
			?>
				var objAmphur=document.frmMain.ddlAmphur;
				for (x=0;x<objAmphur.length;x++)
				{
					if (objAmphur.options[x].value=="<?=$strAmphur?>")
					{
						objAmphur.options[x].selected = true;
						break;
					}
				}
			<?
			}
			?>
	}
</script>
 Dependant List Menu และการกำหนดค่า Default Selected Item (PHP+MySQL)
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-08-27 19:35:30 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ผมทดลองโดยการนำโค้ดเต็มๆที่คุณวินโพสต์ไว้มาใช้ แล้วส่งค่าด้วยซับมิทกับโค้ดด้านล่าง แต่ก็ยังไม่ได้อะครับ Code (PHP)
 
 <?
	if (isset($_POST['submit'])) {
	$linkName ="listbox.php?aid1=".$_POST["ddlAmphur"]."&pid1=".$_POST["ddlProvince"]."&gid1=".$_POST["ddlGeo"];
	exit("<script>window.location='$linkName';</script>");
	}
?>           
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-08-27 22:34:31 | By :
                            Pavich |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วครับ ขอบคุณครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-08-27 23:07:52 | By :
                            pavich |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ก็ว่าอยู่ครับ ผมเขียนไว้แล้วน่ะครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-08-28 07:50:05 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |