954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

drop down list

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.......

hemasow
Newbie Poster
6 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Here is a piece of code with the basic concept for that:

<?
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>';
        }
    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>';
        }
    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>';
        }
    }
echo "<xmp>";
print_r($_POST);
echo "</xmp>";
?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

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....

Attachments 1.bmp (413.07KB)
hemasow
Newbie Poster
6 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Then just use a little javascript to submit the form like the following:

<?
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>';
        }
    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>';
        }
    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>';
        }
    }
echo "<xmp>";
print_r($_POST);
echo "</xmp>";
?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

thank you, wil try this and get to you bac:)

hemasow
Newbie Poster
6 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

hi we tried that code, but didnt work please see the attachment..... and reply us as soon as possible

Attachments 2.txt (1.33KB)
hemasow
Newbie Poster
6 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

I have just adapted the code to your example. A bit of a mind twister making it but here it is:

<?
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>';
        }
    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>';
        }
    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>';
        }
    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>';
        }
    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>';
        }
    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>';
        }
    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>';
        }
    }
echo "<xmp>";
print_r($_POST);
echo "</xmp>";
?>
cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You