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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:14:01+00:00 2026-05-28T08:14:01+00:00

I have three radio buttons and a textfield generated by drupal. What I want

  • 0

I have three radio buttons and a textfield generated by drupal. What I want is for the first two buttons to hide the textfield when they are clicked on, and for the last radio button to show the textfield. (It is used to select an amount of money where the first two options are standard amounts and the last is a custom amount).

I have the following code generated by drupal:

<div class="form-item">
 <label>Jag uppgraderar till: </label>
 <div class="form-radios"><div class="form-item" id="edit-new-amount-no-cost-wrapper">
 <label class="option" for="edit-new-amount-no-cost"><input type="radio" id="edit-new-amount-no-cost" name="new_amount" value="no_cost"   class="form-radio" /> Ingen kostnad</label>

</div>
<div class="form-item" id="edit-new-amount-rounded-wrapper">
 <label class="option" for="edit-new-amount-rounded"><input type="radio" id="edit-new-amount-rounded" name="new_amount" value="rounded"   class="form-radio" /> Avrundat upp</label>
</div>
<div class="form-item" id="edit-new-amount-other-wrapper">
 <label class="option" for="edit-new-amount-other"><input type="radio" id="edit-new-amount-other" name="new_amount" value="other"   class="form-radio" /> Annat belopp</label>
</div>
</div>
</div>
<div class="form-item" id="edit-other-amount-wrapper">
 <label for="edit-other-amount">Annat belopp:: </label>

 <input type="text" maxlength="128" name="other_amount" id="edit-other-amount" size="60" value="" class="form-text" />
</div>

I have tried using this in jquery:

// When clicking on 1st radio button
$('#edit-new-amount-no-cost').change(function(){
  $('#edit-other-amount-wrapper').hide();
});

// When clicking on 2nd radio button
$('#edit-new-amount-rounded-cost').change(function(){
  $('#edit-other-amount-wrapper').hide();
});

// When clicking on 3rd radio button
$('#edit-new-amount-other').change(function(){
  $('#edit-other-amount-wrapper').show();
});

That didn’t work. Only the 3rd button worked.

I also tried looping through them (and setting them all to hide the textfield, even the 3rd button):

$('input[type=radio]').each(function() { 
  alert('Id: '+$(this).attr('id')); // Just to see that the loop works
  $(this).change(function(){
    alert('Id: '+$(this).attr('id')); // Just to see that the function fires
    $('#edit-other-amount-wrapper').hide();
  });
});

That didn’t work either. I even added an alert box to know when the click function executes. The same goes here, it’s only when the 3rd button is clicked something happens.

So my problem is: I can’t set onclick (or onchange, I tried .change as well) for all radio buttons.

Do you have any ideas on what to do?

Kind regards,
Samuel

  • 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-28T08:14:01+00:00Added an answer on May 28, 2026 at 8:14 am

    The ID of the second radio is wrong like kinakuta mentioned but also you might want to hide the text box by default. Have a look at the jsfiddle: http://jsfiddle.net/valanto/fShAv/

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

Sidebar

Related Questions

I want to have three radio buttons, two on one line and one on
In my page I have three radio buttons and I want to checked the
I have a group of three radio buttons. Depending on which radio button is
I have three radio buttons with same name and different values.When I click the
I have three radio buttons, let's call them R1, R2 and R3. (R1 is
I have three radio buttons <input id=RadioJ type=radio name=grp1 class=abc /> <input id=FaroK type=radio
I have 3 file uploads and three radio buttons associated with them. All radio
I have three radio buttons in my Oracle form. Ideally, selecting one option would
Let's say I have three radio buttons: RA, RB, RC On each change value
I have a series of radio buttons (rdoGroup1,rdoGroup2,rdoGroup3) and three textboxes at the end

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.