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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:13:03+00:00 2026-05-16T11:13:03+00:00

I am trying to get dynamic select menu’s working in my Rails application. I

  • 0

I am trying to get dynamic select menu’s working in my Rails application.

I have a model called kase, a model called person and a model called company.

When a user creates a new kase, they are presented with a select field to choose a Person and a select field to choose a Company.

I am trying to make it dynamic, so if they choose company a in the first select field then only employees of company a will be listed in the Person field.

The model associations are as follows:

class Kase < ActiveRecord::Base

  belongs_to :company # foreign key: company_id
  belongs_to :person # foreign key in join table
  belongs_to :surveyor,
             :class_name => "Company",
             :foreign_key => "appointedsurveyor_id"
  belongs_to :surveyorperson,
             :class_name => "Person",
             :foreign_key => "surveyorperson_id"

-------------------------------------------------  

class Company < ActiveRecord::Base
  has_many :kases
  has_many :people
  def to_s; companyname; end

-------------------------------------------------

class Person < ActiveRecord::Base
  has_many :kases # foreign key in join table
  belongs_to :company

UPDATED JAVASCRIPT

var people = new Array();
<% for person in @people -%>
  people.push(new Array(<%= person.company_id %>, '<%=h person.personname %>', <%= person.id %>));
<% end -%>

function personSelected() {
  alert('hello world');
  appointedsurveyor_id = $('kase_appointedsurveyor_id').getValue();
  options = $('kase_surveyorperson_id').options;
  options.length = 1;
  people.each(function(person) {
    if (person[0] == appointedsurveyor_id) {
      options[options.length] = new Option(person[0], person[1]);
      alert('hello world')
    }
  });
  if (options.length == 1) {
    $('kase_surveyorperson_id').hide();
  } else {
    $('kase_surveyorperson_id').show();
  }
}

document.observe('dom:loaded', function() {
  $('kase_appointedsurveyor_id').observe('change', personSelected);
});
  • 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-16T11:13:04+00:00Added an answer on May 16, 2026 at 11:13 am
    var people = new Array();
    <% for person in @people -%>
      people.push(new Array(<%= person.id %>, '<%=h person.login %>'));
    <% end -%>
    
    function personSelected() {
      alert('hello world');
      appointedsurveyor_id = $('company_appointedsurveyor_id').getValue();
      options = $('person_appointedsurveyorperson_id').options;
      options.length = 1;
      people.each(function(person) {
        if (person[0] == appointedsurveyor_id) {
          options[options.length] = new Option(person[0], person[1]);
        }
      });
      if (options.length == 1) {
        $('person_field').hide();
      } else {
        $('person_field').show();
      }
    }
    
    document.observe('dom:loaded', function() {
      //companySelected(); << remove this
      $('person_field').observe('change', personSelected);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to follow this tutorial (http://railscasts.com/episodes/88-dynamic-select-menus) to get dynamic select boxes working
I have a report where I'm trying to get the sum of a dynamic
I want to create a dynamic select input (dropdown menu) from JSON. I have
I have been trying to get a more dynamic solution than naming all dropdowns
EDIT: Database names have been modified for simplicity I'm trying to get some dynamic
I've a crystal report that I'm trying to get a dynamic image displayed. This
I'm trying to make a dynamic array in C# but I get an annoying
I'm trying to select the id's of dynamic input fields in my code. When
I have been trying to create some dynamic Xaml. I have the following c#
I'm trying to get a handle on Entity Framework Performance, specifically around the dynamic

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.