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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:05:15+00:00 2026-06-02T03:05:15+00:00

Trying to dynamically change dropdown list values from mysql database. Script seems like workin

  • 0

Trying to dynamically change dropdown list values from mysql database. Script seems like workin but I’m not sure. The database columns are id, columnA, columnB, columnC, columnD

On second dropdown-list selection, it gives the alert ‘hi again’.

$(document).ready(
function() {
$(".columnA").change(
function() {
    var dataA=$(this).val();
    var dataString = 'columnA='+ dataA;
    $.ajax (    {
                    type: "POST",
                    url: "ajax_try.php",
                    data: dataString,
                    cache: false,
                    success: function(html)
                    {
                        $(".columnB").html(html);
                    }    
                }               
            );

            }
    );

$(".columnB").change(
function() {
    var dataB=$(this).val();
    var dataString = 'columnB='+ dataB;
    $.ajax (    {
                    type: "POST",
                    url: "ajax_try.php",
                    data: dataString,
                    cache: false,
                    success: function(html)
                    {
                        alert("hi.. again");
                        $(".columnC").html(html);
                    }    
                }               
            );

            }
    );

});

<?php
include('db.php');
if($_POST['columnA'])
{
$columnA = $_POST['columnA'];

$sql = mysql_query("SELECT id, columnB FROM try WHERE columnA = '$columnA' GROUP BY columnB");

//$sql = mysql_query("SELECT id, columnB FROM try columnB WHERE columnA = '$columnA'");

while($row = mysql_fetch_array($sql))
{
$id = $row['id'];
$columnB = $row['columnB'];
echo '<option value="'.$id.'">'.$columnB.'</option>';

}
}


if($_POST['columnB'])
{
$columnB = $_POST['columnB'];

$sql = mysql_query("SELECT id, columnC FROM try WHERE columnB = '$columnB' GROUP BY columnC");

while($row = mysql_fetch_array($sql))
{
$id = $row['id'];
$columnC = $row['columnC'];
echo '<option value="'.$id.'">'.$columnC.'</option>';

}
}

?>

Ok I think html code make it easier to understand the problem..

<html xmlns="http://www.w3.org/1999/xhtml">
....
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
.....
here is the script
...
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="10">
  <tr>
    <td width="15%"><span style="font-size:20px;">columnA</span></td>
    <td><span >
        <select size="1" id="columnA" title="" name="columnA" class="columnA"  style="width:250px; height:40px; font-size:20px; padding: 5px;">
            <option value="0" selected="selected">Choose..</option>
        <?php
            include('db.php');
            $sql=mysql_query("SELECT columnA FROM try GROUP BY columnA");
            while($row = mysql_fetch_array($sql))
            {
            //$id = $row['id'];
            $dataA = $row['columnA'];
            echo '<option value="'.$dataA.'">'.$dataA.'</option>';
            } 
        ?>
        </select>
        </span>
    </td>
  </tr>
  <tr>
     <td width="15%"><span style="font-size:20px;">columnB</span></td>
    <td>
        <select size="1" id="columnB"  title="" name="columnB" class="columnB" style="width:250px; height:40px; font-size:20px; padding: 5px;">
            <option value="0" selected="selected">Choose..</option>
        </select>
    </td>
  </tr>
  <tr>
     <td width="15%"><span style="font-size:20px;">columnC</span></td>
    <td>
        <select size="1" id="columnC"  title="" name="columnC" class="columnC" style="width:250px; height:40px; font-size:20px; padding: 5px;">
            <option value="0" selected="selected">Choose..</option>
        </select>
    </td>
  </tr>


</table>
</body>
</html>
  • 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-02T03:05:16+00:00Added an answer on June 2, 2026 at 3:05 am

    I’d be tempted to just select all the rows from your table in one query, and then use JavaScript (or jQuery) to change the select list options. This saves HTTP requests, as for each change your firing an AJAX event, and if the user changes the option 100 times, that’s 100 requests just for aesthetic reasons.

    Another benefit is, if the user for some reason doesn’t have JavaScript or is on a slow connection, then the select lists are still usable, as otherwise they’ll be blank because they haven’t been loaded by your AJAX call.

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

Sidebar

Related Questions

I am trying to change the text color of a button(api: Button) dynamically, but
I'm trying to dynamically change a Border Background property named Brush2, but I get
After dynamically creating a client-side table based on SELECT information retrieved from MySql database,
I am trying to dynamically change my page titles. I have the following script
I am trying to change value of a dropdown dynamically using JQuery.I changed the
I'm currently trying to show a score which requires the text to change dynamically
So I'm trying to dynamically change the style of a div with javascript, which
So I'm trying to dynamically change the opacity of a TextView in my android
I am trying to dynamically change the font and background color of my app
I am trying to dynamically change a picture when I click on it, via

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.