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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:20:12+00:00 2026-06-07T23:20:12+00:00

I’m using CakePHP 1.2.4 and I have two search filters in a search form

  • 0

I’m using CakePHP 1.2.4 and I have two search filters in a search form that interact this way : a dropdownlist is populated with countries and another ddl is populated with the states of the country selected in the first ddl.

This is done with ajax

I need to call the ajax function when the page is refreshed when they’re used in a search form else the states ddl is not populated again.

These dropdownlists are also used in other types of views. For example, on an edit_address.ctp page, the selected values when opening the page would be the ones saved in the database.

However, on the edit_address.ctp page I need not to update the values on refresh (or onload), because I don’t want the states to be updated unless the user change the country manually.

    $('.ajaxSelect').each(function(){
    $(this).change(function(){
        updateSelect($(this));
    });
    //call function on load only for filters in a search form
    if($(this).closest('.frmSearch').length > 0){
        if($(".ajaxSelect option:selected").text() != ""){
            $(this).change(updateSelect($(this))).change();
        }
    }
})

It works fine with this function but then in edit_address.ctp, if the user change the country (without saving it) and refreshes the page, the states are reseted to match the default country BUT the country selected remains the one selected before refreshing so the states don’t match anymore with the country.

Here’s an example of the countries filter

<select id="AddressCountryId" class="ajaxSelect" linked="AddressRegionId" method="getRegion" name="data[Address][country_id]">

And the states filter

<select id="AddressRegionId" name="data[Address][region_id]">

var_dump($_POST) is empty when refreshing so I cannot access selected values this way in the address controller.

The other thing I can think of is, in the ajax function above, to check if the selected state in the view matches the country selected, by calling a method from the model. Is it the right way to go? Should I create a new function in the ajax controller to access the model function instead?

In short, I want the states list to be updated with ajax whenever the selected values do NOT come from the database (unless the user manually selects another country) if it makes sense

There might be some key concept I’m missing. Feel free to ask precisions as it may be confusing, thanks


Edit : I’m guessing this might not be a question of when to make the ajax call or not, but rather how to keep the dropdownlists values and their selected values after refresh (edited the title as well)

  • 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-07T23:20:15+00:00Added an answer on June 7, 2026 at 11:20 pm

    HTTP is stateless. So when you refresh the browser, it is a new HTTP request and it does not have any idea what was the selected item in the dropdown.

    One possible workaround is to store the state in some persistent medium. Session variable ,Database are two options you can think of.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6

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.