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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:43:08+00:00 2026-05-25T01:43:08+00:00

Possible Duplicate: How to dynamically populate options on dropdown lists based on selection in

  • 0

Possible Duplicate:
How to dynamically populate options on dropdown lists based on selection in another dropdown?

I have MySQL tables looking like that

regions table

id     |   region
-------------------
1      |   Region1
2      |   Region2

…

and schools table

id     |   school
-------------------
1      |   schno1
1      |   schno5
1      |   schno6
2      |   scho120

There are multiple select (dropdown) menus in my registration form. The regions dropdown looks like that

<td>
<select name="region" id="region">
<option value="">Region</option>
<?php
$result=$db->query("SELECT * FROM regions");
while($row=$result->fetch_array(MYSQLI_BOTH))
{
    echo '<option value="'.$row[0].'">'.$row[1].'</option>';
    }
?>
</select>

</td>
<td>
<div id="sch_dropdown">
<select name="school" id="school">
<option value="">School</option>
</select>
</div>
<span id="loading"><img src="core/design/img/jquery-ui/loading.gif" width="16" height="16" align="absmiddle">&nbsp;Loading...</span>
<div id="no_sch">No schools found</div>
</td>

I want to populate new dropdown list based on previous selections. What i want to do is, get “regions” id, then populate schools dropdown menu based on id (id of previous selection) from “schools” table on the fly. Here is my code but it doesn’t work.

My js looks like that

$(document).ready(function(){

function populate() {

       fetch.doPost('core/code/includes/search.php');

}

$('#region').change(populate);

var fetch = function() {

var schools = $('#schools');
return {
    doPost: function(src) {

    $('#loading').show();
    $('#sch_dropdown').hide(); 
    $('#no_sch').hide(); 


        if (src) $.post(src, { region_code: $('#region').val() }, this.getschools);
        else throw new Error('No SRC was passed to getCounties!');
    },

    getschools: function(results) {
        if (!results) return;
        schools.html(results);

    $('#loading').hide(); // Hide the Loading...
    $('#sch_dropdown').show(); // Show the drop down
    }   
}
}();

populate();

});

and search.php

if(isSet($_POST['region_code'])) {
$res=$db->query("SELECT * FROM schools  WHERE id='".$_POST['region_code']."'");
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
}

Please help me to finish it. Thx in advance.

  • 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-05-25T01:43:09+00:00Added an answer on May 25, 2026 at 1:43 am

    You’re calling getschools() with no parameter, so it returns nothing. You were supposed to pass the result that you get after making a POST request to the search.php file.

    EDIT:
    I’m not sure that this will work, as I’ve not tested it first. But I think you should change

      if (src) $.post(src, { region_code: $('#region').val() }, this.getschools);
    

    to

       if (src) $.post(src, { region_code: $('#region').val() }, function(data){
           getschools(data);
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can i fix my scrollView dynamically when i have more than
Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Possible Duplicate: How can I access local scope dynamically in javascript? Hi all. We
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Grouping WHERE clauses with Zend_Db_Table_Abstract I need to create something like this:
Possible Duplicate: Is it possible to pass parameters by reference using call_user_func_array()? I have
Possible Duplicate: Dynamically Growing an Array in C++ I want to create a loop
Possible Duplicate: obj-c access property dynamically I'm attempting to access an object’s properties dynamically
Possible Duplicate: .Net Changes the element IDs I have the following problem (I'll explain

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.