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

  • Home
  • SEARCH
  • 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 8425137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:11:23+00:00 2026-06-10T04:11:23+00:00

I am trying to make a form that starts with 3 select drop down

  • 0

I am trying to make a form that starts with 3 select drop down menus. Pretty standard —

The selection of drop down 1 populates the options in drop down 2

Then,

The selection of drop down 2 populates the options in drop down 3

I have followed sled‘s answer to a simular question here, https://stackoverflow.com/a/6864321/766817 but I can’t figure out (using his example), how to add a third element into the mix. Here is what I have so far…

_form.html.erb

<%= select_tag  :first_select,
("<option>Product Grade...</option>" + options_from_collection_for_select(@product_grades, "id", "product_grade")).html_safe,
  :'data-remote' => 'true',
  :'data-url' => url_for(:controller => 'product_grades', :action => 'getdata'), 
  :'data-type' => 'json'
%>

<%= select_tag  :second_select,
  :'data-remote' => 'true',
  :'data-url' => url_for(:controller => 'vendors', :action => 'getdata'), 
  :'data-type' => 'json'
%>

<%= select_tag :third_select %>

application.js

$('#first_select').live('ajax:success', function(evt, data, status, xhr) {

  var selectbox2 = $('#second_select');

  selectbox2.empty();

  $.each(data, function(index, value) {
    var opt = $('<option/>');

    opt.attr('value', value[0]);
    opt.text(value[1]);
    opt.appendTo(selectbox2);
  });
});


$('#second_select').live('ajax:success', function(evt, data, status, xhr) {

  var selectbox3 = $('#third_select');

  selectbox3.empty();

  $.each(data, function(index, value) {
    var opt = $('<option/>');
    opt.attr('value', value[0]);
    opt.text(value[1]);
    opt.appendTo(selectbox3);
  });
});

And finally, I have the getdata actions in both the ProductGradesController and the VendorsController

ProductGradesController

def getdata
  @data_from_select1 = params[:first_select]
  @data_for_select2 = Vendor.where(:product_grade_id => @data_from_select1).all
  render :json => @data_for_select2.map{|c| [c.id, c.vendor_name]}
end

VendorsController

def getdata
  @data_from_select2 = params[:second_select]
  @data_for_select3 = ItemCode.where(:vendor_id => @data_from_select2).all
  render :json => @data_for_select3.map{|a| [a.id, a.item_code]}
end

Currently, the first two steps work, however the third step produces a select box but no data populates it when you select an option from the first two steps.

I am pretty new at jQuery AJAX queries and such, so I am sure I am doing something wrong there, but any ideas? Thanks!!

  • 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-10T04:11:25+00:00Added an answer on June 10, 2026 at 4:11 am

    Okay, so for anybody who encounters a similar issue in the future, I actually ended up taking a different route…

    The amount of data these drop downs will be handling won’t be very much, so I actually integrated a non AJAX’d approach to this with a jQuery plugin called jQuery Chained (https://github.com/tuupola/jquery_chained)

    This simply enables/disables the drop down options depending on the selection made in the previous drop down. This wouldn’t be a very good solution if your drop downs are populated with a lot of db data, or if you needed to have a security layer on what the drop downs show, as the options are added/removed from the DOM, meaning it would be easy for someone to see all of the data by viewing the source code.

    HomeOnRails blog has a great post about how to integrate this jQuery Chained plugin into your rails app. (http://homeonrails.blogspot.com/2012/01/rails-31-linked-dropdown-cascading.html)

    Enjoy and good luck!

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

Sidebar

Related Questions

I am trying to make a form using two drop down select menus: one
I'm trying to make an AJAX form that will update a twitter status when
Trying to make a custom :confirm message for a rails form that returns data
I am trying to make a form field for a datetime property that allows
I am trying to make a form that lets the user choose a date
I kinda have a problem. I'm trying to make a form that copies stuff
I'm trying to make a basic html form that passes information to a php
In a Symfony2 website I'm trying to make a form with 2 (or 3)
I'm fairly new to javascript and I'm trying to make an form for my
I'm trying to make a simple form, but it's working not so fine. This

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.