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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:23:38+00:00 2026-05-17T18:23:38+00:00

I have a set of 3 radio buttons, with these element IDs: id=’details_first’ id=’details_second’

  • 0

I have a set of 3 radio buttons, with these element IDs:

id='details_first'
id='details_second'
id='details_third'

How do I get all the elements whose id starts with 'details_' ?

EDIT

What I’m actually trying to do is this:
Each radio button has an associated div that I want to display when the radio button is clicked. At one time only one radio button is active, so only div for that radio button should be shown (all others should be hidden). So the code for this that I have is:
(sorry, it’s a bit wide):

<input id="details_first" name="details" type="radio" value="first"  onclick="$('details_*').hide();$('details_first_div').show();" />First<br/>
<div id="details_first_div" style="display:none">div for details_first</div>

<input id="details_second" name="details" type="radio" value="second"  onclick="$('details_*').hide();$('details_second_div').show();" />Second<br/>
<div id="details_second_div" style="display:none">div for details_second</div>

Or is there a better best-practice way to do this kind of thing? (I’m using Ruby on Rails).
Maybe by selecting by name attribute – but how ?

  • 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-17T18:23:39+00:00Added an answer on May 17, 2026 at 6:23 pm

    You should create an event handler on the form which manages all the clicks. You should do a selection because you only care for the <input> fields with name == details.

    Then you can hide all the divs in your <form> starting with a specified id, and show only the one with clicked element's id + _div ending.

    Finally you can remove the event handlers from your markup.

    See a working demo.

    var form = $("FORM_ID");
    form.observe( 'click', function(event)  {
      var el = event.element();
      if ( el.name == "details" ) {
        // select: #FORM_ID div#details_*
        idStartsWith("details_", "div", form).invoke("hide");
        $(el.id + "_div").show();
      }
    });
    
    /**
    * Selecting elements by how their id starts
    *
    * @param text - starting of the id
    * @param tag  - filter results by tag name [optional]
    * @param root - root of the selection      [optional]
    */
    function idStartsWith(text, tag, root) {
      root = root || document;
      tag  = tag || "*";
      var arr = root.getElementsByTagName(tag);
      var len = arr.length;
      var ret = [];
      for ( var i = 0; i < len; i++ ) {
        if ( arr[i].id.indexOf( text ) === 0 )
          ret.push(arr[i]);
      }
      return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of radio buttons (individual buttons) in asp.net. These buttons have
I have a set of radio buttons in my page. On the change I
I have a set of radio buttons that are dynamically generated (via JSON call):
I have a set of radio buttons. In some cases I want the user
I have this set of labels and radio buttons that look like this: Entertainment:
i have four radio buttons , and i want to set a text for
I have a set of radio buttons that are for certain products. I am
I have a flex MXML UI that is building a set of radio buttons
I have a set of radio buttons that triggers a jquery function if a
I have two radio buttons <div align=center class=radio_group> <input type=radio id=gallerymenustyle1 class=element radio name=gallerymenustyle[]

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.