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 8903859
In Process

The Archive Base Latest Questions

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

I am looking to get the selected field from a dropdown box in order

  • 0

I am looking to get the selected field from a dropdown box in order to use it in a future dropdown box, but I can’t figure out how to echo the variable through the ajax back to the html.

<p>Trainer</p>
<select name = "trainer_has_update_pokemon">
<option>Select Trainer</option>
<?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>

Pokemon

<select name = "type_of_update_pokemon">
</select>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){ 
    $('select[name="trainer_has_update_pokemon"]').change(function(){ // when trainer_has_update_pokemon changes
        $.ajax({
            type:"POST", //send a post method
            url:'pkmn_dropdown.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>


<select name="nickname_of_update_pokemon">
</select>

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

the php for the name dropdown:

<?php

//connect to db

    $trainer_name = $_POST['trainer_name']; 
    $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();
        echo $trainer_name;
    }?>

The php for the nickname dropdown:

<?php

//connect to db

$pkmn_name = $_POST['pkmn_name']; 
$query = "SELECT p.nickname FROM Pokemon p, Trainer t WHERE p.name = '$pkmn_name AND p.owner_id = t.trainer_id AND t.name = $trainer_name";
if ($stmt = $mysqli->prepare($query)) {
    $stmt->execute();
    $stmt->bind_result($nickname);
    while ($stmt->fetch()) {
        echo"<option>$nickname</option>";
    }
    $stmt->close();
}?>

Any ideas how to get the selected trainer name from the first dropdown box so i can use it in the nickname dropdown box

  • 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-15T01:58:34+00:00Added an answer on June 15, 2026 at 1:58 am

    What exactly is happening when you run the above code? Does the nickname select lose all of it options? Does your ajax response contain the options string as expected?

    Modifying the innerHTML of a select does not work in IE. You will need to add actual elements. Try something like this.

    $( 'select[name="nickname_of_update_pokemon"]' ).empty().append( $( response ) );
    

    In your ajax success function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way to get selected cells count from a specific
I'm looking to get a title of the specific item that is being selected
When looking to get data from a web page whats the recommended method if
I'm looking for a solution to get the first selected item in a DropDownList.
I am looking for a regular expression to validation Date selected from a datepicker
Thanks for looking, I'm trying to get 20 entries from the database randomly and
Looking for a little help trying to get the value of two selected buttons,
I am looking for a safe way to get value of a selected radio
I'm looking to get a Regex for the following password strength requirements: Minimum 8
I'm looking to get an instance of Solr search running on my localhost. The

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.