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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:16:51+00:00 2026-06-02T13:16:51+00:00

can someone please help me with this code, i’m missing something but can’t figure

  • 0

can someone please help me with this code, i’m missing something but can’t figure out what. When you select one of the items in the first list, it brings up the next box but there are no options to select and the same again with the 3rd option although i don’t even get the box to appear this time.

I need about around 10 dropdown lists in total and after each selection has been selected to update the price at the bottom using the price column in the sql table ( I have no idea how to do this) so all your help will be great, been looking at this for at least 4 hours now and i’m getting no where.

Thanks

here is the html:

<body>
<select style="width: 150px;" name="country" id="add-event-dialog-country" onchange="getState(this.value)">
                <?php
                    echo "<option selected='selected' disabled='disabled'> Select Country</option>";
                    $result = mysql_query("SELECT DISTINCT country FROM country");
                    while($row = mysql_fetch_array($result)){
                       echo "<option value='".$row['country']."'>".$row['country']."</option>";
                    }
                ?>
           </select>
           <p id="statediv">
           <select style="width: 150px;" name="add-event-dialog-state" id="add-event-dialog-location" disabled="disabled">
                <option>Select State</option>
           </select>
           </p>
           <p id="citydiv">
           <select style="width: 150px;" name="add-event-dialog-city" id="add-event-dialog-city" disabled="disabled">
                <option>Select City</option>
           </select>
           </p>

Price =<br>
VAT = <br>
Total Price = <br>
</body>

Here’s the js script:

<script language="javascript" type="text/javascript">
function getXMLHTTP() { 
    var xmlhttp=false;  
    try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e)    {       
        try{            
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
    }

    return xmlhttp;
}

function getState(country_Id) {     

    var strURL="findState.php?country="+country_Id;
    var req = getXMLHTTP();

    if (req) {

        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {                        
                    document.getElementById('statediv').innerHTML=req.responseText;                     
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }               
        }           
        req.open("GET", strURL, true);
        req.send(null);
    }       
}

function getCity(country_Id,state_id) {     

    var strURL="findCity.php?country_name="+country_Id+"&state_name="+state_Id;
    var req = getXMLHTTP();

    if (req) {

        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {                        
                    document.getElementById('citydiv').innerHTML=req.responseText;                      
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }               
        }           
        req.open("GET", strURL, true);
        req.send(null);
    }       
}
</script>

Here’s the findState.php

<?php 
include 'classes.php';

$country = $_GET['country'];

$query="SELECT state_name FROM state WHERE country_id='$country'";
$result=mysql_query($query) or die(mysql_error());

?>
<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog- location" onchange="getZone('<?=$country?>',this.value)">
<option selected='selected' disabled='disabled'>Select State</option>
<?php 
while($row = mysql_fetch_array($result)){
echo "<option value='".$row['state_name']."'>".$row['state_name']."</option>";}
?>
</select>

Here’s the findCity.php

<?php 
include 'classes.php';

$country_id = $_GET['country'];
$state_Id = $_GET['state'];

$query="SELECT city_name FROM city WHERE country_id='1' AND state_id='1'";
$result=mysql_query($query) or die(mysql_error());

?>
<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog- location" onchange="getZone('<?=$country?>',this.value)">
<option selected='selected' disabled='disabled'>Select State</option>
<?php 
while($row = mysql_fetch_array($result)){
echo "<option value='".$row['city_name']."'>".$row['city_name']."</option>";}
?>
</select>

My SQL Database has 3 tables

1st table called country with 3 columns
id, country and price

2nd table called state with 4 columns
id, country_id, state_name and price

and 3rd table called city with 5 columns
id, country_id, state_id, city_name and price

  • 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-02T13:16:53+00:00Added an answer on June 2, 2026 at 1:16 pm

    In both findState.php and findCity.php you call the javascript function getZone when the selectlists changes? And I can’t see that you have declared that function any where.

    And you add both the state and city selectlist with the same id. I don’t think that it is the cause of your problems, but it could be later on.

    EDIT:

    It seems you submit the country id in a variable called country_name but you try to access it in php by country and the same happens with findCity

    EDIT 2:

    Try changing your findstate.php to this

    <?php 
    include 'classes.php';
    
    $country = $_GET['country'];
    
    $query="SELECT state_name FROM state WHERE country_id='$country'";
    $result=mysql_query($query) or die(mysql_error());
    
    $country = "'".$country."'";
    echo '<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog- location" onchange="getZone('.$country.',this.value)">';
    echo "<option selected='selected' disabled='disabled'>Select State</option>";
    
    while($row = mysql_fetch_array($result)){
    echo "<option value='".$row['state_name']."'>".$row['state_name']."</option>";}
    echo "</select>";
    ?>
    

    The problem seems to be that php doesn’t recognize that you are trying to insert the country id into the html select element. By echo’ing out everything this should be easier.

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

Sidebar

Related Questions

can someone please help me out writing this code in objective C : function
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Can someone please help me figure out a way to achieve the following (see
Can someone please help with converting this code to plain JS: $(document).ready(function() { $(textarea).bind(keydown,
Can someone please help me decipher this code? It's executing when a user pushed
Can someone please help me simpling this redundant piece of code? if (isset($to) ===
Can someone please help. I have been searching and encountered/modified this code I am
I use this code to merge two images. Can someone please help me to
can someone please help me. why does this return an error: Dim stuff As
Could someone please help explain why I can't get this to work? I properly

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.