i have two combox in my page.first is for division and second for gp.when user selecte division corresponding value shoud me fill from mysql in second combox with out submit my form data.any help..

from rohit

i didn`t understand what u exactly want, ok, if u want to update the second one depending on the first one the here is the code which uses javascript

<?
$res_c=mysql_query("select * from dbtable where parentid=0 and status=1");
echo "<script language=javascript>\n";
echo "function chgselcat() {\n";
echo "var d=document.reg_form;\n";
echo "if(d.cat.value==0) {\n";
	echo "d.subcat.options.length = 0;\n";
	echo "d.subcat.options[0]=new Option(\"Select \",\"\")\n";
echo "}\n";
while($row_c=mysql_fetch_array($res_c,MYSQL_BOTH)){
echo "if(d.cat.value==".$row_c['ad_cid'].") {\n";
		echo "d.subcat.length=0;\n";
		$sub_res=mysql_query("SELECT * from dbtable where parentid=".$row_c['ad_cid']." and status=1 order by catname ");  
		$i=1;
		echo "d.subcat.options[0]=new Option(\"--Select Sub Category-- \",\"\")\n";
		while($sub_row=mysql_fetch_array($sub_res,MYSQL_BOTH)){
			echo "d.subcat.options[".$i."]=new Option('".$sub_row['ads_catname']."','".$sub_row['ad_cid']."');\n";
			$i=$i+1;
		}
echo "}\n";
}
echo "}</script>\n"; 
?>
Member Avatar for langsor

If I understand correctly ...
1. You want to load the page with the form
2. When someone selects an item in Box A
3. Box B is populated with values based on Box A's selected item
4. And not reload the page or submit the form at this time

You can not do this with PHP alone. You would need to submit the form and thus reload the page in order to just use PHP to do this.

The current standard way to do this is to use JavaScript to ...
1. Detect when a new item has been selected in Box A
2. And then make a JavaScript Asynchronous Http Request (AJAX) to a server-side script (PHP) and receive the results of that request.
3. Once the JavaScript receives the results the JavaScript then updates the values of Box B using ...
3a. innerHTML method, or
3b. DOM methods

Hope this helps, let us know if you need more help with this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.