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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:12:38+00:00 2026-05-20T15:12:38+00:00

I have a form with a select box and three text input boxes. When

  • 0

I have a form with a select box and three text input boxes. When the option in the select box changes, I want to update the three text input boxes with values corresponding to the selected option. The values are a model object stored on the server.

I’m using Rails 3 and trying to keep things unobstrusive, but I can’t find a clean way to do this. I’ve come up with a couple horrendous, messy solutions, but nothing clean yet. What would be a good way to tie this all together? In particular, I am having trouble with the select element requesting the model object from the server.

Here’s the view that generates the form:

= form.select :region_id, region_options_for_select(@business_location.region), :prompt => '-- Region --'
= form.text_field :city
= form.text_field :state, :label => 'Province/State'
= form.text_field :country

So I wish to populate the city/state/country fields whenever “region” is changed. Note that region is also part of the form itself.

  • 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-20T15:12:39+00:00Added an answer on May 20, 2026 at 3:12 pm

    In jQuery, something like this could work:

    $("select").live("change", function(e) {
      e.preventDefault();
      $.ajax({
        url: "/location/" + $(this).val(), //I think, it could be something else
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function(data) {
          //you're returning a JSON object, so just iterate through it and bind it to
          //the value attributes of each field
        },
        error: function(xhr,exception,status) {
          //catch any errors here
        }
      });
    });
    

    On the Rails side, in the LocationsController#show:

    @location = Location.find(params[:id])
    respond_to do |format|
      format.json { render :json => @location.to_json, :status => 200 }
    end
    

    That’s roughly how it could work. Substitute whatever the controller/model names you have for the ones I made up.

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

Sidebar

Related Questions

Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
I have a form in which I have 30 input boxes and 10 text
I have a form with a table that has two input boxes, a select
I have this form: <form name=customize> Only show results within <select name=distance id=slct_distance> <option>25</option>
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have an absolutely positioned input box in a form. The input box has
I have a form in Excel with a combo box control. I want the
I have a form with two radiobuttons: [radio1] [radio2] [select] <input type=radio id=radio1 name=radio
I have 4 <select></select> elements in my form. Usually when submitting the form you
I have form that displays several keywords (standard set of choice lists that changes

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.