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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:53:56+00:00 2026-06-17T21:53:56+00:00

I have drop down menu that is populated with different US states. When the

  • 0

I have drop down menu that is populated with different US states. When the user selects different states, it sends this.value to an ajax function that populates another drop down menu filled with the different cities within that state.

The good news is that it works… for the most part. however when I select a state with 2 words such as “New York”, it doesnt find anything. I recon its because there is a white space in the middle. therefore this.value is actually passing only “New” and not “New York”. Below is my PHP code and AJAX function. can anyone tell me what i have missed here?! thanks a million 🙂

        //if result returns a value
if ($result != NULL){

    $row = mysql_fetch_assoc($result);
    $countryCode = $row['Code'];

    if ($countryCode != NULL){

        $sql = "SELECT DISTINCT District FROM City WHERE CountryCode = '$countryCode'";
        $result = mysql_query($sql);

        ?>
        <select name="state" onchange="getCity('<?=$country?>',this.value)">
        <option>Select State</option>

        <? while($row=mysql_fetch_array($result)) { ?>

        <option value="<?=$row['District']?>"><?=$row['District']?></option>

        <? } ?>

        </select>

    <?php

    }


}


function getCity(countryId, stateId) {      
    var strURL="findCity.php?country="+countryId+"&state="+stateId;
    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);
    }
  • 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-17T21:53:57+00:00Added an answer on June 17, 2026 at 9:53 pm

    You should enclose the value in double quotes like this

    <option value="<?=$row['District']?>"><?=$row['District']?></option>
    

    The HTML is by default taking first word as a value and the next word as the name of next attribute which doesn’t have any value. Enclosing it in quotes will make the whole phrase as single value..

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

Sidebar

Related Questions

I have a drop down menu, that a user selects a criteria from, based
So, basically I have this select / drop down menu that I use AJAX
I have a normal WinForms ToolStripDropDownButton's drop down menu that is populated dynamically. In
So I have a drop down menu that's supposed to be populated by a
I have an asp.net webpage with a drop down menu that is populated by
I have a drop down menu that the user can select a location from.
Currently have a drop down menu that is activated on a hover (from display:none
I have a drop down menu that looks great when the page it scrolled
So, I have an animated drop down menu that slides down when your mouse
I have built a drop-down menu here http://dev.driz.co.uk/jsonmenu/ that uses JSON to dynamically build

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.