Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:33:48+00:00 2026-06-15T02:33:48+00:00

I am trying to populate a dropdown box using the selection from another dropdown

  • 0

I am trying to populate a dropdown box using the selection from another dropdown box. I have already figured out how to populate the list using data from the database, it seems the problem is in getting what they have selected from the first dropdown box on the same page without submitting the form. This is what I have so far.

<select name = "trainer_has_update_pokemon">
<p>Trainer</p>
<?php
$query = "SELECT name FROM Trainer";

if ($stmt = $mysqli->prepare($query)) {
$stmt->execute();
$stmt->bind_result($name);
while ($stmt->fetch()) {
    echo"<option>$name</option>";
}


$stmt->close();
}


?>
</select>

<?php
$trainer_name = $_GET['trainer_has_update_pokemon'];
?>

<p>Pokemon</p>
<select name = "type_of_update_pokemon">
<?php
$query = "SELECT DISTINCT p.name FROM Pokemon p WHERE p.owner_id = (SELECT t.trainer_id FROM Trainer t WHERE t.name = '$trainer_name')";
if ($stmt = $mysqli->prepare($query)) {
$stmt->execute();
$stmt->bind_result($pkmn_name);
while ($stmt->fetch()) {
    echo"<option>$pkmn_name</option>";
}
$stmt->close();
}
?>

I don’t really have any experience in Javascript or AJAX, so if there is a way to do this without those, that would be helpful, but if not, I am open to learning their application in this case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:33:49+00:00Added an answer on June 15, 2026 at 2:33 am

    Unfortunately, you will need some sort of client side script to call an external php page in order to pull in the data in real-time. A quick mock up would look something like:

    javascript:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
    $(function(){ //document ready
        $('select[name="trainer_has_update_pokemon"]').change(function(){ // when trainer_has_update_pokemon changes
            $.ajax({
                type:"POST", //send a post method
                url:'ajax.php', // path to ajax page
                data:"trainer_name="+$(this).val(), //set trainer_name to value
                success:function(response){ // retrieve response from php
                    $('select[name="type_of_update_pokemon"]').html(response); // update select
                }
            });
        });
    });
    </script>
    

    PHP (i’ve named ajax.php):

    <?php
    /* ADD YOUR DATABASE CONNECTION */
    $trainer_name = $_POST['trainer_name']; // DONT FORGET TO ESCAPE!!
    $query = "SELECT DISTINCT p.name FROM Pokemon p WHERE p.owner_id = (SELECT t.trainer_id FROM Trainer t WHERE t.name = '$trainer_name')";
    if ($stmt = $mysqli->prepare($query)) {
        $stmt->execute();
        $stmt->bind_result($pkmn_name);
        while ($stmt->fetch()) {
            echo"<option>$pkmn_name</option>";
        }
        $stmt->close();
    }?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to find out how to populate a dropdown box in
I'm trying to get a drop-down box to populate from data within a database,
I am trying to populate a selection box (dropdown) from a mysql table in
I am trying to populate a dropdown list from database. In my view file
I am just trying to populate a html.dropdown list using mvc2 in VS2008. But
I am trying to get the selected option from a dropdown and populate another
I'm trying to populate a JSP dropdown from a database table. Here's the code
Im trying to populate a dropdown list using jquery. The population has but the
I'm trying to populate a dropdown list in my web page from a mysql
I am trying to implement a simple filter from one dropdown box to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.