Dear Mani Bhai.
You can do it easliy by using AJAX. Whenever you select a division from dropdown, an asynchronous request with that division-value can be sent to your server program (responsible for returning related district list). Again, from the district list you can send asynchronous request same way (as previous) to get the related upazillas. And submitting all these data to your form, you can do your desired operation.
Here's a sample code to get and show a one dimensional select-to-select options. I used cpaint framework of AJAX.
/* PHP File -- test.php */
<?php
require_once('you\\path\\ajax\\cpaint.inc.php');
?>
?>
<script language="JavaScript" src="ajax/cpaint.inc.js"></script>
<script language="JavaScript" src="test.js"></script>
<script language="JavaScript" src="test.js"></script>
<form name="test_form" action="test.php" method="POST">
<select name="sel0" OnChange="selFn();">
<option value="-1">Select One</option>
<option value="0">Programming</option>
<option value="1">Scripting</option>
</select>
<select name="sel1" id="sel1" onChange="showAlert(this.value);">
<option value="-1">Select One</option>
</select>
<option value="-1">Select One</option>
</select>
</form>
<?php
//Function for returning languages specified by ID
function SelectLangs($sel){
mysql_connect("localhost","root","");
mysql_select_db("test");
if($sel==0)
$q="SELECT * FROM langs ORDER BY lang_name";
elseif($sel==1)
$q="SELECT * FROM langs WHERE lang_name LIKE 'P%'";
else
return "nothing";
$res=mysql_query($q);
$i=0;
$arr=array();
while($r=mysql_fetch_array($res)){
$arr[$i++]=$r[lang_name].",";
}
$str=implode('',$arr);
$fp=fopen('test8.txt','w');
fwrite($fp, $str, strlen($str));
fclose($fp);
return $str;
} //End of function
mysql_connect("localhost","root","");
mysql_select_db("test");
if($sel==0)
$q="SELECT * FROM langs ORDER BY lang_name";
elseif($sel==1)
$q="SELECT * FROM langs WHERE lang_name LIKE 'P%'";
else
return "nothing";
$res=mysql_query($q);
$i=0;
$arr=array();
while($r=mysql_fetch_array($res)){
$arr[$i++]=$r[lang_name].",";
}
$str=implode('',$arr);
$fp=fopen('test8.txt','w');
fwrite($fp, $str, strlen($str));
fclose($fp);
return $str;
} //End of function
?>
/* End of PHP File*/
/* JS File -- test.js */
var cnt = 0;
function selFn(){
remRows(document.test_form.sel1);
var sel0=document.test_form.sel0.value;
cpaintCall('SELF', 'POST', 'SelectLangs', sel0, checkLangCallBack);
}
remRows(document.test_form.sel1);
var sel0=document.test_form.sel0.value;
cpaintCall('SELF', 'POST', 'SelectLangs', sel0, checkLangCallBack);
}
//Callback function
function checkLangCallBack(arr){
var aa=new Array();
aa=arr.split(",")
for(i=0 ; i<aa.length-1 ; i++)
{
add(aa[i]);
}
}
function add(ele)
{
newOption = new Option (ele, ele);
document.test_form.sel1.options.add(newOption);
cnt++;
}
var aa=new Array();
aa=arr.split(",")
for(i=0 ; i<aa.length-1 ; i++)
{
add(aa[i]);
}
}
function add(ele)
{
newOption = new Option (ele, ele);
document.test_form.sel1.options.add(newOption);
cnt++;
}
/* End of JS File*/
You can get nice AJAX help from here:
Shimul <shimul39@...> wrote:
Dear all, Md. Abul Ahsan (Mani)
I have a problem. Let's say I select a division of Bangladesh from a combo/list box. All districts of that division selected in the next list box. Then if I select a district from that list box all upo-zilla (8/9/10 upa-zill) comes and I make a loop to display their name in a combo box. Each combo has a text box to get the population for each upo-zilla. I give some data in the population text box. After giving all population data and selecting associating upo-zilla then I click submit. Now I want to insert all these upo-zilla id and population in the detail table. Actually I want a VB data grid by PHP.
Thank you in advance.
Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.