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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:12:25+00:00 2026-05-26T22:12:25+00:00

My code below is showing the proper city/state div’s when the matching country is

  • 0

My code below is showing the proper city/state div’s when the matching country is selected from the drop down, but it’s not hiding the previous one if the user decides to select another state. Do I have to create an if/else each for each div i want to hide?

<script type="text/javascript">
$(document).ready(function() {
...
//city & state display 

   $("#ctry").change(function() {
      $(".state").hide();

      var stateSelect = $("#state_" + $(this).val());

      if (stateSelect.length === 0)
         $("#state_label").hide(); 
      else {
         $("#state_label").show();
         stateSelect.show();
      }       
   });     
});
</script>

html code:

    <label>Country/Locale:</label>
        <select id="ctry" name="country">
        <option value="">-- Select</option>
        <option value="US">United States</option>
        <option value="CA">Canada</option>
        <option value="GB">United Kingdom</option>        
        <option value="AU">Australia</option>       
        </select><br /> 

<!-- US -->        
    <div id="state_US" style="display:none">
    <label id="state_label" style="display:none">State:</label>
    <span class="rstate">
        <select name="u_state">
        <option value="">-- State US</option>
        <option value="AL">Alabama</option>
        </select>
    </span>
    &nbsp;&nbsp;Zip or City:<input style="margin-left:43px;" type="text" name="locus" id="locus" size="30" />
    </div>

<!-- CA -->   
    <div id="state_CA" style="display:none">
    <label id="state_label" style="display:none">Province:</label>
    <span class="rstate">
        <select name="c_state">
        <option value="">-- Prov CA</option>
        <option value="ON">Windsor</option>
        </select>
    </span>
    &nbsp;&nbsp;Postal or Place:<input style="margin-left:43px;" type="text" name="locca" id="locca" size="30" />
    </div>

<!-- GB -->
    <div id="state_GB" style="display:none">
        <label id="state_label" style="display:none">City or Region:</label>
        <span class="rstate">
            <select name="k_state">
            <option value="">-- Place</option>
            <option value="AU">UK!</option>
            </select>
        </span>
    </div>

<!-- AU -->
    <div id="state_AU" style="display:none">
        <label id="state_label" style="display:none">City or Region:</label>
        <span class="rstate">
            <select name="a_state">
            <option value="">-- Place</option>
            <option value="AU">UK!</option>
            </select>
        </span>
    </div>
  • 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-26T22:12:26+00:00Added an answer on May 26, 2026 at 10:12 pm

    Remove the state_label ids..
    Add the unused class state to the state_CA, state_US etc. elements..

    So each state group should be

    <div id="state_US" class="state" style="display:none">
    <label style="display:none">State:</label>
    <span class="rstate">
        <select name="u_state">
        <option value="">-- State US</option>
        <option value="AL">Alabama</option>
        </select>
    </span>
    &nbsp;&nbsp;Zip or City:<input style="margin-left:43px;" type="text" name="locus" id="locus" size="30" />
    </div>
    

    And change your script to be

    <script type="text/javascript">
    $(document).ready(function() {
    ...
    //city & state display 
    
       $("#ctry").change(function() {
          $(".state").hide();
    
          var stateSelect = $("#state_" + $(this).val());
          stateSelect.show();      
       });     
    });
    </script>
    

    Demo at http://jsfiddle.net/gaby/PYx2v/

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

Sidebar

Related Questions

The code below will display the city, state chosen by user from previous page
Please help me understand, the below code is showing Type mismatch: cannot convert from
Below code only showing the textfield, but I want to include textfield and textarea.
Can anyone please tell me why the code below is not showing the div
I try the search code below but it is only showing the first child
a div has few image and the code below is showing one image at
Iam using xCode 4.3.2, In my count-down timer project (code showing below), i want
I am loading a cell from a xib directly using code below but the
The code below demonstrates trying to log req.hash_id from middleware. It's showing up for
Code below is used to save PostgreSql database backup from browser in Apache Mono

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.