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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:02+00:00 2026-06-15T23:56:02+00:00

In a simple form: <%= form_for @user do |f| %> <%= f.label :source, How

  • 0

In a simple form:

<%= form_for @user do |f| %>
  <%= f.label :source, "How did you find out about us?", :class => "control-label" %>
  <%= f.select(:source, options_for_select([['--  Please select  --',nil],['Source 1','Source 1'], ['Source 2','Source 2'], ['Other','Other']])) %>

  <%= f.label :source_other, "Specify Other Source" %>
  <%= f.text_field :source_other %>
<% end %>

I am trying to learn how to use JQuery to only show the “source_other” text field when the value “Other” is selected from the “source” field. From what I’ve seen online, it looks like I need to use something like this:

$("#source").change(function() {
  if ($("#source").val()=="Other")
    $("#source_other").show();
  else
    $("#source_other").hide();
});

However, I am not quite understanding how to integrate the JQuery with my form. Could someone please point me in the right direction?

Updated:

Here is the resulting html snippet:

<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
  <label class="control-label" for="user_lead_source">How did you find out about us?</label>
  <select id="user_source" name="user[source]"><option value="">--  Please select  --</option>
    <option value="Source 1">Source 1</option>
    <option value="Source 2">Source 2</option>
    <option value="Other">Other</option>
  </select>

  <label for="user_source_other">Specify Other Source</label>
  <input id="user_source_other" name="user[source_other]" size="30" type="text" />
</form>
  • 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-15T23:56:03+00:00Added an answer on June 15, 2026 at 11:56 pm

    I am suspecting that your server code doesn’t generate an ID for the element, in which case your selectors are looking for elements with ID’s that don’t exist

    If that is the case either add an ID with your server code so your jQuery ID selectors will work or use name= selectors

    $(function(){
        $('input[name="source"]').change(function() {
          $('input[name="source_other"]').toggle(  $(this).val()=="Other" );
    
        });
    });
    

    As long as jQuery code is wrapped in $(document).ready() or $(function(){}); which is shorthand for same, you can place it anywhere in page in a script tag so long as it is after after jQuery library has loaded . Or you can put it in extrnal file that loads after jQuery

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

Sidebar

Related Questions

I was creating sixth form for a simple one digit user input and it
please help me with a simple PHP doubt. I have a simple form: <
I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have a repeater that displays a custom user control on a form multiple
I am trying to create simple user registration form. I have an index.html file
I have a simple html form for the user confirmation. Once the user registers
I have a simple form for a hotel accommodation tool. User selects the number
I have a simple form for generating reports that I am adding a jqueryUI
I have a simple form that looks like this: <%= simple_form_for @study,:url => studies_path,
I have a simple form that looks like so <% remote_form_for post, :url =>

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.