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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:34:49+00:00 2026-05-31T14:34:49+00:00

I have a rails form. I have 4 check boxes. What I am trying

  • 0

I have a rails form. I have 4 check boxes. What I am trying to do is, hide 3 of the check boxes on page load. And when the 4th check box is checked show the hidden ones. And when the check box is unchecked, again hide the 3 check boxes.

This is what I have so far;

The HTML code generated from the rails form:

<table>
<tr>
   <td><label for="Question 1">Question 1?</label></td>
    <td><input default="false" id="question1" name="question1" onclick="showOptions()" type="checkbox" value="1"/></td>
</tr>
<tr>
   <td></td>
   <td>
      <input id="option1" name="option1" type="checkbox" value="idoption1"/>
      <label for="Option 1">Option 1</label>
   </td>
</tr>
<tr>
   <td></td>
   <td>
      <input id="option2" name="option2" type="checkbox" value="idoption2"/>
      <label for="Option 2">Option 2</label>
   </td>
</tr>
<tr>
   <td></td>
   <td>
      <input id="option3" name="option3" type="checkbox" value="idoption3"/>
      <label for="Option 3">Option 3</label>
   </td>
</tr>
</table>

And the javascript

<script type = "text/javascript" >

$(document).load(function() {
    $('#option1').hide()
    $('#option2').hide()
    $('#option3').hide()
});

function showOptions() {
    if $('#question1').checked() {
        $('#option1').show()
        $('#option2').show()
        $('#option3').show()
    }
}

< /script>

This doesn’t work. What is wrong? 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-31T14:34:50+00:00Added an answer on May 31, 2026 at 2:34 pm

    Try changing the if condition as if ($('#question1').is(':checked') ){

    DEMO

    A better approach is to hide all checkbox and it contents using css and then add/remove class based on question checkbox selection. See below code,

    DEMO

    CSS:

    .hideContents input, .hideContents label { display: none; }
    

    HTML: Add class to all those td's that has checkbox which needs to be hidden.

    <td class="hideContents">
    

    JS:

    $('#question1').on ('change', showOptions);
    
    function showOptions() {
        if ($('#question1').is(':checked') ){
            $('.hideContents')
                .removeClass('hideContents')
                .addClass('showContents');
        } else {
            $('.showContents')
                .removeClass('showContents')
                .addClass('hideContents');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to submit a Rails form with AJAX. I have some toggle on/off
I have a rails layout form with multiple partials making up the page: Layout:
We have the following code working for a complex rails form with checkboxes. I'm
I have a Rails form for email, and I would like to have auto-completion
I have a simple Ruby on Rails form which includes an authenticity_token. Unfortunatly, I
I have some code to display a long list of languages inside Rails form
I would like to have Ajax form in Rails so i'm using form_remote_tag. The
I have a live rails website and I want to have a form with
I'm making a simple search form in rails. In my search view I have
I have a complex form in Ruby on Rails 2.3.5, here's the structure for

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.