drop down list

Reply

Join Date: Mar 2009
Posts: 6
Reputation: hemasow is an unknown quantity at this point 
Solved Threads: 0
hemasow hemasow is offline Offline
Newbie Poster

drop down list

 
0
  #1
Mar 30th, 2009
hi
we have one problem while using drop down list in PHP. We have a drop down list, after the selection of the items in that drop down list we want another drop down list to be displayed based on the selection of the first drop down list, we r not able to generate the second drop down list...... please help us and reply soon.......
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,452
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is online now Online
Nearly a Posting Virtuoso

Re: drop down list

 
0
  #2
Mar 30th, 2009
Here is a piece of code with the basic concept for that:
  1. <?
  2. echo '<form method="post">
  3. <select name="box1">
  4. <option value="apple">Apple
  5. <option value="orange">Orange
  6. <option value="lemon">Lemon
  7. </select><input type="submit" value="Submit"></form>';
  8.  
  9. if (isset($_POST['box1'])) {
  10. if ($_POST['box1']=='apple') {
  11. echo '<form method="post">
  12. <select name="box2">
  13. <option value="1">1
  14. <option value="2">2
  15. <option value="3">3
  16. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  17. <input type="submit" value="Submit"></form><br>';
  18. }
  19. if ($_POST['box1']=='orange') {
  20. echo '<form method="post">
  21. <select name="box2">
  22. <option value="4">4
  23. <option value="5">5
  24. <option value="6">6
  25. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  26. <input type="submit" value="Submit"></form><br>';
  27. }
  28. if ($_POST['box1']=='leamon') {
  29. echo '<form method="post">
  30. <select name="box2">
  31. <option value="1">1
  32. <option value="3">3
  33. <option value="5">5
  34. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  35. <input type="submit" value="Submit"></form><br>';
  36. }
  37. }
  38. echo "<xmp>";
  39. print_r($_POST);
  40. echo "</xmp>";
  41. ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 6
Reputation: hemasow is an unknown quantity at this point 
Solved Threads: 0
hemasow hemasow is offline Offline
Newbie Poster

Re: drop down list

 
0
  #3
Mar 31st, 2009
hi thank you for the reply but actual thing we want is to display a drop down list as soon as we select the item in the first drop down list ie the second drop down list should change based on the selection of the first.
also we dont want the drop down to change after we click the submit button

as shown in the attachment we want the 2nd drop down list to be displayed based on the selection of the 1st drop down list...
please reply as early as possible....
Attached Images
File Type: bmp 1.bmp (413.1 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,452
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is online now Online
Nearly a Posting Virtuoso

Re: drop down list

 
0
  #4
Mar 31st, 2009
Then just use a little javascript to submit the form like the following:
  1. <?
  2. echo '<form method="post" name="form1">
  3. <select name="box1" onchange="document.form1.submit()">
  4. <option value="apple">Apple
  5. <option value="orange">Orange
  6. <option value="lemon">Lemon
  7. </select></form>';
  8.  
  9. if (isset($_POST['box1'])) {
  10. if ($_POST['box1']=='apple') {
  11. echo '<form method="post">
  12. <select name="box2">
  13. <option value="1">1
  14. <option value="2">2
  15. <option value="3">3
  16. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  17. <input type="submit" value="Submit"></form><br>';
  18. }
  19. if ($_POST['box1']=='orange') {
  20. echo '<form method="post">
  21. <select name="box2">
  22. <option value="4">4
  23. <option value="5">5
  24. <option value="6">6
  25. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  26. <input type="submit" value="Submit"></form><br>';
  27. }
  28. if ($_POST['box1']=='leamon') {
  29. echo '<form method="post">
  30. <select name="box2">
  31. <option value="1">1
  32. <option value="3">3
  33. <option value="5">5
  34. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  35. <input type="submit" value="Submit"></form><br>';
  36. }
  37. }
  38. echo "<xmp>";
  39. print_r($_POST);
  40. echo "</xmp>";
  41. ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 6
Reputation: hemasow is an unknown quantity at this point 
Solved Threads: 0
hemasow hemasow is offline Offline
Newbie Poster

Re: drop down list

 
0
  #5
Mar 31st, 2009
thank you, wil try this and get to you bac
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 6
Reputation: hemasow is an unknown quantity at this point 
Solved Threads: 0
hemasow hemasow is offline Offline
Newbie Poster

Re: drop down list

 
0
  #6
Mar 31st, 2009
hi we tried that code, but didnt work please see the attachment..... and reply us as soon as possible
Attached Files
File Type: txt 2.txt (1.3 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,452
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is online now Online
Nearly a Posting Virtuoso

Re: drop down list

 
0
  #7
Mar 31st, 2009
I have just adapted the code to your example. A bit of a mind twister making it but here it is:
  1. <?
  2. echo '<form action="test_insert.php" method="POST" name="form1" style="margin:0px; padding:0px;">
  3. <select size=3 multiple="multiple" name="category[]" onchange="document.form1.submit()">
  4. <option value="Noun">Noun</option>
  5. <option value="Pronoun">Pronoun</option>
  6. <option value="Adjective">Adjective</option>
  7. <option value="Adverb">Adverb</option>
  8. <option value="Adp">Adp</option>
  9. <option value="Conjunction">Conjunction</option>
  10. <option value="Inter/Particles">Inter/Particles</option>
  11. </select></form>';
  12.  
  13. if (isset($_POST['category'][0])) {
  14. if (in_array('Noun',$_POST['category'])) {
  15. echo '<form method="post">
  16. <select name="box2">
  17. <option value="1">1
  18. <option value="2">2
  19. <option value="3">3
  20. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  21. <input type="submit" value="Submit"></form><br>';
  22. }
  23. if (in_array('Pronoun',$_POST['category'])) {
  24. echo '<form method="post">
  25. <select name="box2">
  26. <option value="4">4
  27. <option value="5">5
  28. <option value="6">6
  29. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  30. <input type="submit" value="Submit"></form><br>';
  31. }
  32. if (in_array('Adjective',$_POST['category'])) {
  33. echo '<form method="post">
  34. <select name="box2">
  35. <option value="1">1
  36. <option value="3">3
  37. <option value="5">5
  38. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  39. <input type="submit" value="Submit"></form><br>';
  40. }
  41. if (in_array('Adverb',$_POST['category'])) {
  42. echo '<form method="post">
  43. <select name="box2">
  44. <option value="21">21
  45. <option value="22">22
  46. <option value="23">23
  47. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  48. <input type="submit" value="Submit"></form><br>';
  49. }
  50. if (in_array('Adp',$_POST['category'])) {
  51. echo '<form method="post">
  52. <select name="box2">
  53. <option value="91">91
  54. <option value="92">92
  55. <option value="93">93
  56. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  57. <input type="submit" value="Submit"></form><br>';
  58. }
  59. if (in_array('Conjunction',$_POST['category'])) {
  60. echo '<form method="post">
  61. <select name="box2">
  62. <option value="94">94
  63. <option value="95">95
  64. <option value="96">96
  65. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  66. <input type="submit" value="Submit"></form><br>';
  67. }
  68. if (in_array('Inter/Particles',$_POST['category'])) {
  69. echo '<form method="post">
  70. <select name="box2">
  71. <option value="31">31
  72. <option value="32">32
  73. <option value="33">33
  74. </select><input type="hidden" name="box1" value="'.$_POST['box1'].'">
  75. <input type="submit" value="Submit"></form><br>';
  76. }
  77. }
  78. echo "<xmp>";
  79. print_r($_POST);
  80. echo "</xmp>";
  81. ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
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