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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:48+00:00 2026-05-26T18:31:48+00:00

I have used a jQuery script and some php code to generate two select

  • 0

I have used a jQuery script and some php code to generate two select menus.
One menu has states and the other regions. Once the states menu is changed the correspknding regions are loading.
My question is how to set a default value of “all cities”. The script automatically loads the
regions that finds in the mysql table so i cant find a way to do that.
I guess i have to change something on the script. Any ideas will be helpful.

 $(document).ready(function(){

 function populate() {

if($('#states').val() == 'AK' || $('#states').val() == 'DC') // Alaska and District Columbia have no counties
{
   $('#county_drop_down').hide();
   $('#no_county_drop_down').show();
} else {

   fetch.doPost('../getCounties.php');

}

}

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

 var fetch = function() {

 var counties = $('#search_area');

 return {
doPost: function(src) {

$('#loading_county_drop_down').show(); // Show the Loading...
$('#county_drop_down').hide(); // Hide the drop down
$('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case)


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

getCounties: function(results) {
    if (!results) return;
    counties.html(results);

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

 populate();

});

  • 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-26T18:31:48+00:00Added an answer on May 26, 2026 at 6:31 pm

    You don’t mention if “All Cities” is in your DB or not so I’m assuming it is not. Also I’m not sure what you’re returning exactly so I’m going to assume that counties is a select input.

    Untested answer but perhaps it will help.

    After the county list is returned you can prepend the “All” option to the list, and then select it…The only other thing you’d have to do then is make sure whatever is handling this form on the server knows what to do with “All”.

    getCounties: function(results) {
        if (!results) return;
        var allCities = $("<option value=\"All\">All Cities</option>");
    
        counties.html(results);
        counties.prepend(allCities);
        counties.val("All").attr('selected',true);
    
        $('#loading_county_drop_down').hide(); // Hide the Loading...
        $('#county_drop_down').show(); // Show the drop down
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some jquery script which runs after the window has loaded $(window).load( function()
I am working on some website , i have used jQuery UI , for
I have some onchange events setup in jQuery which are used to populate a
I have some JQuery code that shows or hides a div. $(div#extraControls).show(); // OR
I am modifying some code that has a lot of jQuery but I am
I have coded a php script that is used to check the status of
I have used a jQuery script in order to have a countdown script on
I have two web pages which work basically the same, code-wise, but one of
I have a php website, in which I have used a lot of jquery
I have used JQuery for a small animation work: a table #photos contains 9

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.