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

  • Home
  • SEARCH
  • 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 8146229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:55:33+00:00 2026-06-06T13:55:33+00:00

I have three select boxes state,city and locality with the id’s same as name

  • 0

I have three select boxes state,city and locality with the id’s same as name

$(document).ready(function() {
    $("#state").on('change',function(){
        var state = $("#state").attr('value');
        $("#city").load('http://localhost/trial/index.php/new/view_cities/'+state).change();
    }).change();

    $("#city").on('change',function(){
        var city = $("#city").attr('value');
        $("#locality").load('http://localhost/trial/index.php/new/view_localities/'+city);
    }).change();
});

On page load state gets correctly shown because it’s directly from database, and city options gets automatically updated, but localities do not. And when i change city the localities can change.

  • 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-06T13:55:36+00:00Added an answer on June 6, 2026 at 1:55 pm

    The .load() function is just a wrapper for a call to $.ajax() which is asynchronous; if you’re trying to interact with the elements loaded into the element as a result of that call, you’ll need to pass a callback function that executes once the AJAX request has returned a successful response.

    Try replacing:

    $("#city").load('http://localhost/trial/index.php/new/view_cities/'+state).change();
    

    with

    $("#city").load('http://localhost/trial/index.php/new/view_cities/'+state, 
    function() {
        $("#city").change();
    });
    

    And a couple of general points:

    You can use this inside a function for an event handler to refer to the element that triggered the event. Rather than:

    $("#state").on('change',function(){
        var state = $("#state").attr('value');
    

    you could do:

    $("#state").on('change',function(){
        var state = this.value;
    

    Also, if you are going to use jQuery to get the value of an element, use the .val() function rather than .attr('value').

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

Sidebar

Related Questions

I have 3 chain select boxes that return three values from the same line
I have three select boxes. <div style='float: left; padding-right: 10px;'> <select size=10 name=company_id> //
I have three select boxes :- select1 select2 select3 , i am fetching data
I have the following HTML markup:- <select name=List1 id=l1> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option>
Edit I think this what the OP meant i have three select boxes with
I have 3 select boxes, all populated with the same data. Using jquery I
I have a Zend form with three select boxes. When the form is first
I have a form with a select box and three text input boxes. When
I have multiple select boxes in my document and some of them are load
I have multiple select boxes on the page all of which share the same

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.