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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:18:51+00:00 2026-05-22T22:18:51+00:00

I have in my rails form the following code: <label>Fruit: </label> <%= f.select(:IST_FRUIT, [[‘Apple’,

  • 0

I have in my rails form the following code:

<label>Fruit: </label>  <%= f.select(:IST_FRUIT, [['Apple', 'Apple'],
                          ['Orange', 'Orange'],
                          ['Kiwi', 'Kiwi'],
                          ['Other', 'Other']
                          ],{ :prompt => "Please select"},{:onchange => "if (this.value == 'Other') 
                                                                         {document.getElementById('otherTissue').style.display = 'block';
                                                                         } "}
                          ) %>

<span id="otherFruit" style="display:none;"> If other, please state: <%= f.text_field :IST_FRUIT, :size => 10  %></span>

User can select a fruit form the listbox but if user selects ‘Other’, a textfield is diaplayed allowing user to input his value.

The problem is that when user selects a fruit and save the form, the fruit field in blank in the table and the reason is that the form is saving the second field ‘IST_FRUIT’ found in the span with id ‘IST_FRUIT’.

I would be really grateful if someone could show me a way how to disable the second field when ‘other’ is not selected and enable it when ‘Other’ is selected from the dropdown list.

Many many thanks for any suggestion provided.

  • 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-22T22:18:52+00:00Added an answer on May 22, 2026 at 10:18 pm

    First, be aware that rails posts are based on fields’ name, not ids.

    In your case, you should use a virtual attribute to store the potential other fruit value.

    Your model could look like:

    attr_accessor :other_fruit
    
    before_save :check_fruits
    
    def check_fruits
      #if other_fruit is not nil, it means that you want to store it's value in you IST_FRUIT column 
      #BTW, why these capital letters?
      IST_FRUIT = other_fruit unless other_fruit.nil?
    end
    

    And your form would be:

    <span id="otherFruit" style="display:none;"> If other, please state: <%= f.text_field :other_fruit, :size => 10  %></span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have the following code working for a complex rails form with checkboxes. I'm
I have the following form code: <input data-color=orange id=vote_color_id_2 name=color type=radio value=2 />Orange <input
I have the following code form.label :artists which outputs <label for=artist_artist_name>Artist name</label> How did
I have a Rails form, where I am trying to insert a Select formfield
I have some code to display a long list of languages inside Rails form
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
In rails 3, how to create a Dropdown from hash I have following code
I have the following code in my form. <%= f.datetime_select(:date_time, :prompt => {:day =>
In Rails 3, suppose I have the following code: Controller ... format.js # create.js.erb
In my Ruby on Rails code, I have the following edit.html.erb file for tasks:

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.