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.......
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
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><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>";
?>
hemasow 0 Newbie Poster
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....
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with x-ms-bmp files.
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
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><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>";
?>
hemasow 0 Newbie Poster
thank you, wil try this and get to you bac:)
hemasow 0 Newbie Poster
hi we tried that code, but didnt work please see the attachment..... and reply us as soon as possible
<form action="test_insert.php" method="POST">
Grammatical Information : <br><br>
         
         
         
<select size=3 multiple="multiple" name="category[]" >
<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>
This is our actual code, since we have already used form tag for inserting, we r not able to include another form as in your code
-----------------------------------------------------------------------------------------------------------------------
if (isset($_POST['category']))
{
if ($_POST['category']=='Noun')
{
echo '<form method="post">
<select name="box2">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<input type="hidden" name="category" value="'.$_POST['category'].'">
</form>
<br>';
}
}
cwarn23 387 Occupation: Genius Team Colleague Featured Poster
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><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>";
?>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.