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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:16:35+00:00 2026-05-21T10:16:35+00:00

I have a form that allows the user to choose a country. Depending on

  • 0

I have a form that allows the user to choose a country. Depending on which country is selected, I need to change the State/Province drop-down to include either a list of states or a list of provinces. I was going about this using the observe_field tag, but that was depreciated in rails 3…

So.., how should one go about this now? I am using select_tag to populate the drop-downs, and the arrays used in the options_for_select are all stored server-side and made accessible in the controller action, so I can’t access them from javascript..

  • 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-21T10:16:36+00:00Added an answer on May 21, 2026 at 10:16 am

    Using the Carmen gem: https://github.com/jim/carmen.

    I did the following some times ago (AJAX).

    HTML:

        <p>
            <label>Country <span>*</span></label>
            <%= profile_form.select(:country,Carmen.countries, {:include_blank => 'Select a Country'}, :id => "profile_country") %>
        </p>
        <p>
            <label>State <span>*</span></label>
            <%= profile_form.select(:state,  "" , {:include_blank => 'Select a Country first'}, :id => "profile_state") %>
        </p>
    

    Controller:

    def states
      begin
        render :json => Carmen::states(CGI::unescape(params[:country]))
      rescue 
        render :json => {"content" => "None"}.to_json
      end
    end 
    

    Javascript with jQuery:

    $('#profile_country').change(function() {
        if ($(this).val() == '')
        {
          $('#profile_state').empty();
          $('#profile_state').append( $('<option>No state provided for your country</option>'));
        }
        else {
            $.ajax({
                type: "GET",
                url: "/remote/get_states/" + encodeURIComponent($(this).attr('value')),
                success: function(data){
                    if (data.content == 'None')
                    {
                        $('#profile_state').empty();
                      $('#profile_state').append( $('<option>No state provided for your country</option>'));
                    }
                    //handle the case where no state related to country selected
                  else
                 {
                    $('#profile_state').empty();
                    $('#profile_state').append( $('<option>Select your State</option>'));
                    jQuery.each(data,function(i, v) {
                     $('#profile_state').append( $('<option value="'+ data[i][1] +'">'+data[i][0] +'</option>'));
                });
            }
            }
          });
        }
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form, which allows the user to change dependencies between two kinds
I have a form that allows a user to import a spreadsheet. This spreadsheet
I have a form that allows me to enter a user into my database.
I have a TextBox in a Windows Form that allows a user to enter
I have a bound form in microsoft access that allows a user to add
I have a page that allows a user to choose some things in a
I have a form that allows a user to update their profile information, but
I have a form that allows the user to add as many upload forms
I have a rails3 form that allows the user to edit a list of
I have a django form that allows a user to select multiple options: CARDS

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.