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

10 Years
Discussion Span
Last Post by langsor

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";
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 ");  
		echo "d.subcat.options[0]=new Option(\"--Select Sub Category-- \",\"\")\n";
			echo "d.subcat.options[".$i."]=new Option('".$sub_row['ads_catname']."','".$sub_row['ad_cid']."');\n";
echo "}\n";
echo "}</script>\n"; 

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.