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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:19+00:00 2026-05-26T08:36:19+00:00

I have a ruby on rails application.I have 2 drop down boxes.I have to

  • 0

I have a ruby on rails application.I have 2 drop down boxes.I have to populate the second drop down box based on the selection from the first one.

The html code is

-Releases = Release.all
  %table.grid.full
    %tr      
      %td.grid.full_panels{:style => "width: 40%"}
        Release:
      %td.grid.full_panels{:style => "width: 40%"}
        = select_tag "releases",options_from_collection_for_select(releases,"id","name",params[:releases]),:include_blank=>true
      %td.grid.full_panels{:style => "width: 40%"}
        Cycle:
      %td.grid.full_panels{:style => "width: 40%"}

Now i need the cycles drop down to be populated from releases.

Please help me with the jquery for this.

  • 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-26T08:36:20+00:00Added an answer on May 26, 2026 at 8:36 am

    Basically you should add an event handler that will be triggered when the first drop-down is being changed that populates the second one based on the first one’s selected option :

    $('select#first').change(function(e){
        var newOptions = getNewOptions($(this).val());
        $('select#second').html('');   // clear the existing options
        $.each(newOptions,function(i,o){
            $('<option>' + o + '</option>').appendTo('select#second');
        });            
    });
    
    function getNewOptions(val){
        if (val == 1)
            return ['a','b','c'];
        if(val == 2)
            return [1,2,3,4];
        return ['a1','a2','a3'];
    }
    

    And of course, your html markup is something like :

    <select id="first">
        <option>1</option>
        <option>2</option>
        <option>3</option>
    </select>
    
    <select id="second">
    </select>
    

    Here’s a working demo :

    http://jsfiddle.net/gion_13/Udf5N/

    If you want to query the server for the new option list, in the change event handler, you should do an ajax request to the script that evaluates the current value of the first select-box and returns a list of options for the second one. In this ajax request callback you update the actual html based on the response :

    $('select#first').change(function(e){
        $.getJson('script_name',{value : $(this).val()},function(result){
            $('select#second').html('');   // clear the existing options
            $.each(result,function(i,o){
                $("<option>" + o + "</option>").appendTo("select#second");
            }); 
        });            
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby On Rails application. I want to enable the drop down
I have a ruby on rails application.I am using jquery to populate a drop
I have the Ruby on Rails-based application Redmine (based on the BitNami redmine package)
I have a ruby-on-rails application, which shows a modal dialog form for first-time users.
The Setup I have a Ruby on Rails application that I manage from a
I have a ruby on rails application and it would be nice to see
I have created a table in my Ruby on Rails application that I am
I have to to deploy a Ruby on Rails application to an tomcat application
I have created a blog application using Ruby on Rails which includes the ability
I have created a simple blog application with Ruby on Rails. The applications consists

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.