php combobox

Reply

Join Date: Oct 2007
Posts: 36
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 2
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

php combobox

 
0
  #1
Sep 9th, 2008
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
Last edited by rohitrohitrohit; Sep 9th, 2008 at 7:44 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: php combobox

 
0
  #2
Sep 9th, 2008
you can get good solutions here:
http://www.daniweb.com/forums/thread132703.html
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 171
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 21
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: php combobox

 
0
  #3
Sep 9th, 2008
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
  1. <?
  2. $res_c=mysql_query("select * from dbtable where parentid=0 and status=1");
  3. echo "<script language=javascript>\n";
  4. echo "function chgselcat() {\n";
  5. echo "var d=document.reg_form;\n";
  6. echo "if(d.cat.value==0) {\n";
  7. echo "d.subcat.options.length = 0;\n";
  8. echo "d.subcat.options[0]=new Option(\"Select \",\"\")\n";
  9. echo "}\n";
  10. while($row_c=mysql_fetch_array($res_c,MYSQL_BOTH)){
  11. echo "if(d.cat.value==".$row_c['ad_cid'].") {\n";
  12. echo "d.subcat.length=0;\n";
  13. $sub_res=mysql_query("SELECT * from dbtable where parentid=".$row_c['ad_cid']." and status=1 order by catname ");
  14. $i=1;
  15. echo "d.subcat.options[0]=new Option(\"--Select Sub Category-- \",\"\")\n";
  16. while($sub_row=mysql_fetch_array($sub_res,MYSQL_BOTH)){
  17. echo "d.subcat.options[".$i."]=new Option('".$sub_row['ads_catname']."','".$sub_row['ad_cid']."');\n";
  18. $i=$i+1;
  19. }
  20. echo "}\n";
  21. }
  22. echo "}</script>\n";
  23. ?>
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: php combobox

 
0
  #4
Sep 9th, 2008
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
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC