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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:03:00+00:00 2026-06-18T02:03:00+00:00

peace be with you All, i am new to using Ajax , the issue

  • 0

peace be with you All, i am new to using Ajax , the issue is, i am having 3 drop down lists connected to a database, the first one is “name” and the second one is “age” and the third one is “country”! so, i have connected to the database, and retrieved data from it in the first list “name” and then using Ajax, i have successfully retrieved matching data after selecting any option of first list and put them into the second list called “age”, the problem is that when i use a very exact same way with the second list called “age” to retrieve matching data into third list called “country” it doesn’t work! so please help me cuz, i am using this example to learn Ajax and then apply on a larger real project! here is the code :- firstly, the home.php page:-

<?php
include "config.php";
?>
<html> 
<head> 
<script type="text/javascript">
function agematch() {
 if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} 
 else {
 xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
 }

xmlhttp.onreadystatechange = function() {
  if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

  document.getElementById('age').innerHTML = xmlhttp.responseText;
  }

} 
xmlhttp.open('GET', 'connection.inc.php?name='+document.ajax.name.value, true );
xmlhttp.send();

}

function countrymatch() {
 if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} 
 else {
 xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
 }

xmlhttp.onreadystatechange = function() {
  if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

  document.getElementById('country').innerHTML = xmlhttp.responseText;
  }

} 
xmlhttp.open('GET', 'country.inc.php?age='+document.ajax.age.value, true );
xmlhttp.send();

}

</script>
</head>
<body> 
<form id="ajax" name="ajax" > 
Choose your name : <select name="name" id="name" select="selected"  onchange="agematch();"> <option>  </option> 
 <?php

   $query = "SELECT DISTINCT name FROM info";
   $result = mysql_query($query);
   while($row = mysql_fetch_array($result)){
   echo"<option  value ='".$row[0]."'> '".@$row[0]."'</option>";
                                }   
 ?>
</select>
Age : <select id="age" name="age" onchange="countrymatch();">  </select>
country : <select id="country" name="country"> <option> </option> </select>

</form>
</body>
</html>

now, the page for first Ajax call :-

<?php
include "config.php";
echo " <option>  </option> " ;
if(isset( $_GET['name']) ) {
  @$name = $_GET['name'];
  }

  $query = "SELECT age FROM info WHERE name = '".@$name."' "; 
  $result = mysql_query($query);
    while ($query_row = mysql_fetch_array($result)) {

      echo " <option  value ='".$query_row[0]."'> $query_row[0]</option> ";
      }

 ?>

Now, with the page for the second Ajax call for the third drop menu :-

<?php
include "config.php"; 

  if (isset( $_GET['age']) ) {
     @$age=$_GET['age'];
   }     

  $query = "SELECT country FROM info WHERE name='".@$name."' AND age='".@$age."'  ";
  $result= mysql_query($query);
  while  ($query_row = mysql_fetch_array($result)) {

   echo " <option value = '".$query_row[0]."'> $query_row[0] </option> ";

  }

 ?>

so as you see, here is the code, and of course i am connected to the database through a page called “config.php”, so i want you to help me to solve this issue and retrieve the data from database into the third drop down list “country”. Thanks 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-06-18T02:03:01+00:00Added an answer on June 18, 2026 at 2:03 am

    You are not passing name in the second call.

    Replace

    xmlhttp.open('GET', 'country.inc.php?age='+document.ajax.age.value, true );

    with

    xmlhttp.open('GET', 'country.inc.php?age='+document.ajax.age.value+'&name='+document.ajax.name.value, true );

    Hope that helps.

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

Sidebar

Related Questions

Twofold question. Using a web template that utilizes AJAX for loading new pages, rather
I am using jQuery to submit my form via AJAX. This updates a database
Currently i have a build process in place for all of our apps using
I'm using AJAX.NET including update panels, web service calls, client controls etc. In may
I am pretty new at this stuff, so bear with me. I am using
For the current app I am writing I have elected to place all database
I have an application that is using ajax calls for loading the content. Those
I am writing an application that converts an ajax xml response into html using
Hi I'm building my first MVC 2 app and I'm really confused by all
I'm new to using Moq and I cannot find the way for doing this.

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.