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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:38:47+00:00 2026-05-19T04:38:47+00:00

I have created an html form. it consist of several drop down list for

  • 0

I have created an html form. it consist of several drop down list for (countries,states,cities,areas)

the drop down list for countries looks like this.

Select Countries : <select name="countries" id="countries" onchange="showStates()">
<?php
foreach($crud->getAll('countries') as $countries) 
{ 
?>
    <option value="<?php echo $countries['id']; ?>"><?php echo $countries['name']; ?></option>
<?php } ?>
</select>

and the drop down list for states look like this.

Select State : <select name="states">
<?php
foreach($property->getStatesFromCountryId($countryId) as $states) 
{ 
?>
    <option value="<?php echo $states['id']; ?>"><?php echo $states['name']; ?></option>
<?php } ?>
</select>

the countries drop down list will fetch all the countries from the database and populate it. but in the states drop down list it needs the parameter to be passed dynamically from the country value.

for that i would like to achieve the following

1) hold the id of the country from the countries drop down list in a javascript countryId variable. the code should look something like this var countryId = document.getElementById("countries").value;

2) pass the parameter to foreach($property->getStatesFromCountryId($countryId) as $states) from countryId variable.

how do i achieve it?

  • 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-19T04:38:47+00:00Added an answer on May 19, 2026 at 4:38 am

    Three ways I can think of to do this:

    1. Store all the states for every country in a big JS file as a JS object. Then read from this during the onChange event on the country dropdown.

    2. Store all the states serverside, use AJAX (XMLHttpRequest) to dynamically retrieve the states for the chosen country.

    3. Submit your form in the onChange, passing in a hidden variable to signify to your serverside script it should only fill the State dropdown, not do the rest of the validation yet.

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

Sidebar

Related Questions

I have created and html form which have a drop down list. This drop
When you have an ASP.Net MVC form created by Html.BeginForm(), how do fields inside
I have created a populated dropdown list in HTML. When the two dropdowns have
I have created a simple layout using the HTML div tag. I would like
I have created test form here: http://www.sitecdn.net/clients/repcow/form_min.html Code for checkboxes looks like: <div class=optIn>
I have an HTML form which consists of several fieldsets (each has identical fields).
I have created one html form with following fields: Name (Text Box) Email (Text
I have created a form maker somewhat like Formtorch for codeigniter. The form consists
I have created a Django app. I have a registration page(simple HTML form) in
I have created a simple html-based web-page consisting of a form and some text,

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.