| | |
drop down list
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 6
Reputation:
Solved Threads: 0
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.......
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.......
Here is a piece of code with the basic concept for that:
php Syntax (Toggle Plain Text)
<? echo '<form method="post"> <select name="box1"> <option value="apple">Apple <option value="orange">Orange <option value="lemon">Lemon </select><input type="submit" value="Submit"></form>'; if (isset($_POST['box1'])) { if ($_POST['box1']=='apple') { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="2">2 <option value="3">3 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if ($_POST['box1']=='orange') { echo '<form method="post"> <select name="box2"> <option value="4">4 <option value="5">5 <option value="6">6 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if ($_POST['box1']=='leamon') { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="3">3 <option value="5">5 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } } echo "<xmp>"; print_r($_POST); echo "</xmp>"; ?>
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
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
•
•
Join Date: Mar 2009
Posts: 6
Reputation:
Solved Threads: 0
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....
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....
Then just use a little javascript to submit the form like the following:
php Syntax (Toggle Plain Text)
<? echo '<form method="post" name="form1"> <select name="box1" onchange="document.form1.submit()"> <option value="apple">Apple <option value="orange">Orange <option value="lemon">Lemon </select></form>'; if (isset($_POST['box1'])) { if ($_POST['box1']=='apple') { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="2">2 <option value="3">3 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if ($_POST['box1']=='orange') { echo '<form method="post"> <select name="box2"> <option value="4">4 <option value="5">5 <option value="6">6 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if ($_POST['box1']=='leamon') { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="3">3 <option value="5">5 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } } echo "<xmp>"; print_r($_POST); echo "</xmp>"; ?>
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
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
I have just adapted the code to your example. A bit of a mind twister making it but here it is:
php Syntax (Toggle Plain Text)
<? echo '<form action="test_insert.php" method="POST" name="form1" style="margin:0px; padding:0px;"> <select size=3 multiple="multiple" name="category[]" onchange="document.form1.submit()"> <option value="Noun">Noun</option> <option value="Pronoun">Pronoun</option> <option value="Adjective">Adjective</option> <option value="Adverb">Adverb</option> <option value="Adp">Adp</option> <option value="Conjunction">Conjunction</option> <option value="Inter/Particles">Inter/Particles</option> </select></form>'; if (isset($_POST['category'][0])) { if (in_array('Noun',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="2">2 <option value="3">3 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Pronoun',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="4">4 <option value="5">5 <option value="6">6 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Adjective',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="1">1 <option value="3">3 <option value="5">5 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Adverb',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="21">21 <option value="22">22 <option value="23">23 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Adp',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="91">91 <option value="92">92 <option value="93">93 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Conjunction',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="94">94 <option value="95">95 <option value="96">96 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } if (in_array('Inter/Particles',$_POST['category'])) { echo '<form method="post"> <select name="box2"> <option value="31">31 <option value="32">32 <option value="33">33 </select><input type="hidden" name="box1" value="'.$_POST['box1'].'"> <input type="submit" value="Submit"></form><br>'; } } echo "<xmp>"; print_r($_POST); echo "</xmp>"; ?>
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
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
![]() |
Similar Threads
- php mysql drop down list (PHP)
- drop down list question. (ASP.NET)
- Populate One Drop Down List From Another (ASP.NET)
- Populating a Drop-down List (PHP)
- view employee info for the employee selected from the drop down list (PHP)
- Data Binding to a Drop Down List? (ASP.NET)
- Passing a drop down list item's value (HTML and CSS)
- Blank drop list (PHP)
Other Threads in the PHP Forum
- Previous Thread: Retrieve table contents
- Next Thread: Mysql row delete using php
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube






