0

I have a form whereby dropdown 2 is populated as a result of the selection made in another select dropdown 1. If dropdown 1 one had options A, B & C (separate call from the database) if I select A the application will do a GET with A as a variable and populate the dropdown 2 with the returned results.

I was thinking this could be done in a number of ways but have not quite figured out which direction to take. The first approach I was going to take is to perform the calls straight away and add values associated with A, B and C to dropdown 1 so when it is activated the additional values populate dropdown 2. Additionally i was also trying to figure how to fire a HTTP GET call dynamically based on user hitting the first select.

Can anyone give some pointers about how to achieve this.

EDIT

An example of how we perform HTTP gets

def get_call(routePath)
  started_at = Time.now
  enc_url = URI.encode("#{settings.abacus_service_endpoint}#{routePath}")
  uri = URI.parse(enc_url)
  http = Net::HTTP.new(uri.host, uri.port)

  req = Net::HTTP::Get.new(uri.request_uri, get_header_for_abacus_service)     
  resp = http.request(req)
  logger.bench 'SERVICE - GET', started_at, routePath
  return resp if response_ok?(resp)
end
user3385136
  • 513
  • 1
  • 7
  • 20

2 Answers2

1

have you tried looking at rbates railscast on dynamic select menus. If you havent then please look at it. In is railscast he populates states/provinces depending on the selected country, if it sounds like what you want to achieve them here is the link.

http://railscasts.com/episodes/88-dynamic-select-menus

Hope it helps you.

kalibbala
  • 498
  • 6
  • 12
0

You can do two things

  1. Using jQuery's change event make an ajax request to get the data for another select and populate the options.

  2. Put the other select in a partial and render it

Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78
  • Could you elaborate on the use of partials? We're currently performing our HTTP requests via the following types of methods so want to keep doing that so dont want to perform AJAX requests via jQuery at this time. – user3385136 Aug 05 '15 at 11:09
  • Really stuck on this still so any clarification regarding using partials to achieve this would be much appreciated and would definitely get a tick! – user3385136 Aug 06 '15 at 08:51