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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:11:18+00:00 2026-05-13T09:11:18+00:00

I have a multi select box in a form. the elements in this select

  • 0

I have a multi select box in a form. the elements in this select box is being added/removed from javascript using DOM (e.g. http://www.digimantra.com/tutorials/add-append-remove-value-in-select-html-element-using-javascript/).
I want to get all the elements in the select box inside controller when form submitted.

is there any easy way to do it?

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-05-13T09:11:18+00:00Added an answer on May 13, 2026 at 9:11 am

    The list of possible choices in a select box is not preserved in the form submission, only the selected options are sent.

    The only way to send the list of options in the select box at the time of submission is to add/remove hidden tags listing the choices/values.

    If you’re updating the select DOM element by adding option children with Javascript than you should have too much farther to go. Just have the javascript that adds or removes an option to/from the list add or remove hidden fields to/from the form.

    IE:

    Assuming form created by this partial:

    <% from_for @user do |f| %>
      <%=f.collection_select :selected_values, Values.all, :id, :name %>
      <% Values.all.each do |v| %>
      <%= hidden_field_tag "user[select_options][#{v.name}]", v.id %>
    <% end %>
    
    <%= link_to_function "Add Twenty option",
       '$("select").insert(bottom: "<option value=\"20\">twenty</option>");
        $("form").insert(bottom: "<input type="hidden\" id=\"user_select_options_twenty\" 
          name=\"user[select_options][twenty]\" value=\"20\">"' 
    %>
    
    <%= link_to_function "Remove Twenty option", 
       '$("select").select(\'[value="twenty"]\').remove(); 
        $("#user_select_options_twenty").remove()' 
    %>
    

    Assuming you populate hidden values for the initial select statement on page load this upon submit, params[:user][:select_options] will contain a hash of all the select options availble. The keys in this hash are the options shown, and the values of the hash are the values of those select options.

    Note: posted code is untested. It may not be right, but it should be enough to put you on the right track.

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

Sidebar

Ask A Question

Stats

  • Questions 314k
  • Answers 314k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I am not actually able to produce this error. However… May 13, 2026 at 11:06 pm
  • Editorial Team
    Editorial Team added an answer Use robotlegs, simple and Singleton free! May 13, 2026 at 11:06 pm
  • Editorial Team
    Editorial Team added an answer This feels a bit like a slide show. As such,… May 13, 2026 at 11:06 pm

Related Questions

I have the following multi-select box in a HTML form, where user can select
I need to allow users to choose/input authors associated with a given publication and
I am trying to get John Resig's jQuery Live Search with Quicksilver Style to
Given the following models (cut down for understanding): class Venue(models.Model): name = models.CharField(unique=True) class
First I'll lay out what I'm trying to achieve in case there's a different

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.