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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:24:36+00:00 2026-05-31T15:24:36+00:00

In a Rails 3 app using Jquery, I’m trying to dynamically show/ hide form

  • 0

In a Rails 3 app using Jquery, I’m trying to dynamically show/ hide form elements, based on whether a boolean field is true or false.

At present my jquery function looks something like this:

$(function() {
    $('#boolean').change(function(){
        if ($(this).value == true) {
            $('.hidden-fields').show();
        } else {
            $('.hidden-fields').hide();
        }
    });
})

How do I correctly pass the boolean fields value into this function such that:

  1. the function is initialized on page load, and fields hidden/shown
    based on the value in the database; and
  2. the fields are toggled when the boolean is changed.

Sorry of this is a simple question. I’m trying to get to grips with javascript and really appreciate any pointers.

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-31T15:24:37+00:00Added an answer on May 31, 2026 at 3:24 pm

    Do you only have one element on your HTML page with an id of boolean? Because using #boolean will return the first one only. If you have many, you should use a class of boolean instead, and then use .boolean to reference all elements with that class.

    But to your questions:

    1) Your example code there will be run on page load and will automatically apply to all elements with a .boolean class (assuming you go that way). If you want to immediately hide or show elements because, say, a value in the DB is set to false, then you should do that when you’re rendering your page in your ERB or HAML or whatever view.

    2) If the element you’re attaching this JS to is a select box or something that will have a change() function, then you’re all set to go. If you’re wondering if, when the DB changes, this view automatically changes its visibility, then that is something different.

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

Sidebar

Related Questions

I'm using jquery-ui datepicker on a User DOB field in a Rails 3.2 app.
I am using the jQuery Form Plugin with my Rails app. I have a
I'm running a ruby on rails app, and I'm using jQuery to show some
I'm trying to write an app using Ruby on Rails and I'm trying to
I'm using Rails 3.1 and trying to add some ajax functionality (using jquery +
In a rails 3 app using Jquery and JqueryUI, I'm rendering a partial to
I'm using a jquery-ui datepicker in a Rails 3 app. The datepicker is currently
I have jquery working on my Rails app using the gem 'jquery-rails' . I
I am using the JQuery Autocomplete UI with my rails app and it is
I want to create person objects in my rails app using a jquery ajax

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.