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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:23:25+00:00 2026-05-29T13:23:25+00:00

I am trying to associate a radio input with a specified text input. As

  • 0

I am trying to associate a radio input with a specified text input. As you can see in the picture, there are two options. I know I can use for="" to associate the label to the radio input, but how can I also associate it to the text input underneath, and vise versa so when I focus on the text input, if focuses the correct radio button?

Radio and text input

NOTE: The amount entered will be inserted into the database, so that’s the most important part of this form. Currently if I click on $Off, I can still enter a number in %Off. I don’t want this to happen, so the user does not get confused.

My markup:

<div class="row-fluid control-group">
  <div class="span7 pull-left">
    <label class="radio" for="discount-dollars">
      <input type="radio" name="discount" id="discount-dollars" value="dollars" checked="checked">
      &#36; Off
    </label>
    <div class="input-append">
      <input type="text" name="discount-dollars-amount" id="discount-dollars-amount" class="input-small dollars" placeholder="enter amount">
      <span class="add-on">.00</span>
    </div>
  </div><!-- .span7 .pull-left -->

  <div class="span5">
    <label class="radio" for="discount-percent">
      <input type="radio" name="discount" id="discount-percent" value="percent">
      &#37; Off
    </label>
    <input type="text" name="discount-percent-amount" id="discount-percent-amount" class="input-small percent" placeholder="enter amount" disabled="disabled">
  </div>
</div><!-- .row-fluid .control-group -->

<script type="text/javascript">

$(function (){
  $("form input[type=radio]").click(function (){

  // get the value of this radio button ("dollars" or "percent")
  var value = $(this).val();

  // find all text fields...
  $(this).closest("form").find("input[type=text]")

    // ...and disable them...
    .attr("disabled", "disabled")                     

  // ...then find the text field whose class name matches
  // the value of this radio button ("dollars" or "percent")...
  .end().find("." + value)

    // ...and enable that text field
    .removeAttr("disabled")          
  .end();
  });
});

</script>
  • 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-29T13:23:25+00:00Added an answer on May 29, 2026 at 1:23 pm

    You can’t use a single <label> element to label two separate inputs. I would suggest associating the labels to the radio buttons, since the radio button is such a small click target and the label expands that target.

    Choose one of the radios to be selected by default, perhaps “$ Off”. Disable the other text field by default:

    <div class="row-fluid control-group">
      <div class="span7 pull-left">
        <label class="radio" for="discount-dollars">
          <input type="radio" name="discount" id="discount-dollars" value="dollars" checked="checked">
          &#36; Off
        </label>
        <div class="input-append">
          <input type="text" name="discount-dollars-amount" id="discount-dollars-amount" class="input-small dollars" placeholder="enter amount">
          <span class="add-on">.00</span>
        </div>
      </div><!-- .span7 .pull-left -->
    
      <div class="span5">
        <label class="radio" for="discount-percent">
          <input type="radio" name="discount" id="discount-percent" value="percent">
          &#37; Off
        </label>
        <input type="text" name="discount-percent-amount" id="discount-percent-amount" class="input-small percent" placeholder="enter amount" disabled="disabled">
      </div>
    </div><!-- .row-fluid .control-group -->
    

    Then use jQuery to do something like this:

    $(function (){
      $("#discount-dollars, #discount-percent").click(function (){
    
        // get the value of this radio button ("dollars" or "percent")
        var value = $(this).val();
    
        // find all text fields...
        $(this).closest(".control-group").find("input[type=text]")
    
          // ...and disable them...
          .attr("disabled", "disabled")                     
    
        // ...then find the text field whose class name matches
        // the value of this radio button ("dollars" or "percent")...
        .end().find("." + value)
    
          // ...and enable that text field
          .removeAttr("disabled")          
        .end();
      });
    });
    

    Basically, this listens for click events on both radio buttons. When you click one radio, it enables its associated text field (i.e., the text field with a CSS class name matching the value of the radio button) and disables the other text field. That way, you can’t enter text into either text field unless its associated radio button is checked.

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

Sidebar

Related Questions

I am trying to associate Contacts with Classes but as two different types. Current_classes
I'm trying to use CFBundleDocumentTypes to associate a custom file extension with my application.
I have two classes I'm trying to associate, and on runtime I get the
I'm starting a new application in rhodes and I'm trying to associate two tables.
I'm trying to create a global (singleton) class that can associate any type of
This is my first time making a hash table. I'm trying to associate strings
I'm trying to join two associative arrays together based on an entry_id key. Both
I'm trying to build some HTML with Knockout that Jquery UI can turn into
I am trying to associate existing records while still being able to add new
I'm trying to associate an SQLite3 database file with our app so that it's

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.