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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:20:43+00:00 2026-05-24T21:20:43+00:00

I have been searching for a good way to create dynamic dropdowns that are

  • 0

I have been searching for a good way to create dynamic dropdowns that are part of a form. The dropdowns need to be populated with data from the database based on the previous dropdown. I have not found a good rails 3/prototype solution. I have seen some partial solutions with jQuery and using prototype legacy helpers. However, I read it is not a good idea to use the legacy helpers so I am trying to do it without them while still using prototype.

I understand this is a large question however, I assume this has already been done several times and if somebody has a good how to it would be much appreciated. If not my plan of attack is use onchange to trigger a javascript call to send a request to the server. Then update the partial, the next select box, with the apropriate options and then repeat.

Immediate Question: How do you generate a ajax page call using prototype? I need to send the result of the first drop down to my controller. The url would be car_infos/update_make/”year”.

I have this select tag in my larger form that calls a javascript function.

    <%= select_tag 'year', options_from_collection_for_select(@vehicle_years, "year", "year"), {:include_blank => true, :onchange => "submitYear(this.value)" }%>

Thanks for any help as I get started with Rails.

Update: I am generating a request to the server with this javascript:

  function submitYear(year){
    new Ajax.Request('/udpate_make/'+year, {method: 'get'});
}

However, it doesn’t generate the correct url. If I put /car_infos/update_make it generates car_infos/car_infos/udpate_make/. If I take at the /car_infos part it just does /update_make and leaves off the car_infos. I get two or none. Still not sure how to generate the proper url of ‘car_infos/update_make/year’ I will implement the observe option as mentioned by @Jaryl but still having problems with the url generation. Here is my routes…

resources :car_infos

match 'car_infos/update_make/:year', :controller => 'car_infos', :action => 'update_make'

Update: with another part of the journey

To solve the duplicate part of the url I had to do the following:

    function submitYear(year){
    new Ajax.Request('update_make/'+year, {method: 'get'});
}

Notice the missing / from the previous example. Still don’t know why when putting car_infos in there it duplicates it. but at least I am generating a valid Ajax request to the server now.

  • 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-24T21:20:45+00:00Added an answer on May 24, 2026 at 9:20 pm

    This is what I ended up doing to create my dynamic drop downs with Protoype in case anybody else is going down this path. Please let me know if there is a better way:

    Create Routes for appropriate controller, my controller is car_infos

        match 'car_infos/update_make/:year', :controller => 'car_infos', :action => 'update_make'
    match 'car_infos/update_model/:year/:make', :controller => 'car_infos', :action => 'update_model'
    

    Inside form have first dropdown built and render a partial.

        <div id="year_sel">
        <%= f.label :car_year %>
        <%= select_tag 'year', options_from_collection_for_select(@vehicle_years, "year", "year"), {:include_blank => true, :onchange => "submitYear(this.value)" }%>
      </div>
      <div id="make_select">
        <%= render 'make_sel' %>
      </div>
    

    Build the link in javascript in your application.js file:

        function submitYear(year){
        new Ajax.Request('update_make/'+year, { method: 'get'});
    }
    

    Have your .js.rjs file that responds to the ajax request and renders the partial.

    page.replace_html('make_select', render('make_sel'))
    

    In your controller function make sure it responds to the .js format.

    Hope this helps somebody else since it took me two days to find all.

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

Sidebar

Related Questions

I have been searching for a way to get the json data from a
Good day, I have been searching for a way to format output using writeline/write
I have been searching high and low for a way to get my silverlight
I have been searching for a way to insert linebreaks in my code for
I have been searching everywhere but I could not find an answer. I need
How to continue from where I have been searching to find the index? I
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been having some trouble finding a good way to output just the
I have been searching for a way to skin C# applications under Windows Forms.
I need some help, i have been searching around and cant find the correct

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.