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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:50:30+00:00 2026-05-21T21:50:30+00:00

My goal is to build a script that will reveal different paragraphs on a

  • 0

My goal is to build a script that will reveal different paragraphs on a page, depending on the radio button that is clicked.
The first stage is to build a script that will simply reveal one piece text when one of the buttons is clicked.
From reading about this it appears that you should be able to identify which button is clicked by using the ID of the input element and ‘checked. Note that I’m anticipating relying on the ID’s so that I know which text to reveal.
However, the following code is not working and being a neophyte I’m struggling to see what’s missing. Note that for what seems a simpler approach at the beginning I’m showing the text on the page and then want the text to hide when the button is clicked.

The script is

<script type="text/javascript">
    $(document).ready(function() {
    if($('input:checked #category1')) {
        $("#hideCategory1").hide();
            };
        });

The input section is:

      <form name="categories" action="" method="post">
  <h2>Categories
  </h2>
  <p><input name="category" type="radio" value="errorInText" id="category1" />Content</p>
  <p><input name="category" type="radio" value="errorInDesign" id="category2" />Design Problem</p>
  <p><input name="category" type="radio" value="brokenLink" id="category3" />Broken Link</p>
  </form>

CSS is

#hideCategory1 {
visibility: visible;

}

Text Section is

<p id="hideCategory1" class="hidden">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>

I’d appreciate any pointers on why this might be failing and how to correct it.

Note that when I started this I was anticipating using “change” to detect which button was clicked. However, I read in several places that the “change” function sometimes has problems with IE – but I don’t know.

Thanks

UPDATE:
Based on Edgar’s response I reversed the process and added one more line that resets all the text to hidden when a radio button is clicked. Initial tests show this to be working as expected.

$(document).ready(function() {
  $("#hideCategory1, #hideCategory2, #hideCategory3").hide(); //Hide all forms
$(":radio[name='category']").click(function(){
  $("#hideCategory1, #hideCategory2, #hideCategory3").hide();//on click rehide all the forms
   switch($(this).attr("id")){//Select the form based on the radio button that was clicked.
      case "category1": $("#hideCategory1").show(); break;
      case "category2": $("#hideCategory2").show(); break;
      case "category3": $("#hideCategory3").show(); break;
   }
 });
});

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-21T21:50:31+00:00Added an answer on May 21, 2026 at 9:50 pm

    I didn’t understand if you want to show or hide the paragraphs. Anyway, this code hides the paragraph corresponding to the radiobutton clicked. Here you have:

    <html>
    <body>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    $(document).ready(function() {
       $(":radio[name='category']").click(function(){
           $("#hideCategory1, #hideCategory2, #hideCategory3").show(); //Show all paragraphs first.
           switch($(this).attr("id")){
              case "category1": $("#hideCategory1").hide(); break;
              case "category2": $("#hideCategory2").hide(); break;
              case "category3": $("#hideCategory3").hide(); break;        
           }
       });
    });
    </script>
    
    <form name="categories" action="" method="post">
      <h2>Categories
      </h2>
      <p><input name="category" type="radio" value="errorInText" id="category1" />Content</p>
      <p><input name="category" type="radio" value="errorInDesign" id="category2" />Design Problem</p>
      <p><input name="category" type="radio" value="brokenLink" id="category3" />Broken Link</p>
    </form>
      <p id="hideCategory1"> Paragraph 1 </p>
      <p id="hideCategory2"> Paragraph 2 </p>
      <p id="hideCategory3"> Paragraph 3 </p>
    </body>
    </html>
    

    Hope this helps. Cheers

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

Sidebar

Related Questions

My goal is to build an engine that takes the latest HL7 3.0 CDA
I'm trying to write a PowerShell script that will do the following: Executes a
Okay, so my goal is to build a easy to use protocol for sending
My goal is to integrate testing into my development environment (as post-build step). I
How can you automatically import the latest build/revision number in subversion? The goal would
For homework, I need to build a small java application.The main goal is to
I want to build an iOS application that recognizes patterns in a cup of
i'd like to add a media library to a custom-made CMS that is build
My original goal was to get a php file to execute on a button
My ultimate goal is to build a web crawler capable of downloading all of

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.