How to disable buttons based on which radio button is selected?

Goran Tesic

I have 3 div groups, each containing a radio button, a label, and a button. I would like to be able to enable the button within the same group as the selected radio button, and make the buttons from other groups disabled.

<div class="row">
  <div class="col-md-6">
    <!-- when this radio button is checked... -->
    <input id="input-1" type="radio" name="disable-button" checked="checked">
    <label for="input-1">Input 1</label>
    <!-- this button is enabled -->
    <button type="button">ADD</button>
    <!-- ...and vice versa -->
  </div>
  <div class="col-md-6">
    <!-- when this radio button is not checked... -->
    <input id="input-2" type="radio" name="disable-button">        
    <label for="input-2">Input 1</label>
    <!-- ...this button should be disabled -->
    <button type="button" disabled>ADD</button>
    <!-- ...and vice versa -->
  </div>
  <div class="col-md-6">
    <!-- when this radio button is not checked... -->
    <input id="input-3" type="radio" name="disable-button">
    <!-- ...this button should be disabled -->
    <label for="input-3">Input 1</label>
    <button type="button" disabled>ADD</button>
    <!-- ...and vice versa -->
  </div>
</div>

Is there a way to do this via jQuery?

edit: I would prefer the solution to be dynamic if possible in case I have to add more groups.

spencer.sm

I would use the following jQuery code:

$('input[type=radio]').change(function(){
  $('button').prop('disabled', true);
  $(this).parent().find('button').prop('disabled', false);
});

https://jsfiddle.net/dotspencer/6reL64ss/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to swap the displayed image based on which radio button is selected?

From Dev

How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery)

From Dev

How to check if radio buttons are selected on button click?

From Dev

How to know which radio button is selected in jquery?

From Dev

How to show set of Radio buttons based on a previous Radio Button

From Dev

How to show set of Radio buttons based on a previous Radio Button

From Dev

how to know which radio button id selected of which row?

From Dev

Disable submit button until one in a group of dynamically-created radio buttons selected

From Dev

Disable submit button until one in a group of dynamically-created radio buttons selected

From Java

How can I know which radio button is selected via jQuery?

From Dev

How to find out which radio button the user selected in Javascript?

From Dev

How to check which radio button is selected if they're all runat server?

From Dev

How to retrieve which radio button within a LI is selected

From Dev

how to know which radio button is selected out of all options?

From Dev

How to check which radio button is selected if they're all runat server?

From Dev

How to toggle enable/disable input field based on radio button

From Dev

Disable text area if radio button is selected?

From Dev

Disable text area if radio button is selected?

From Dev

jQuery selected radio button index among different sets of radio buttons

From Dev

Having some trouble getting which radio button is selected and issuing a command based on the selection

From Dev

How to style selected radio button

From Dev

How to post selected values from multiple group of radio buttons which generated dynamically

From Dev

Show a dropdown based on proper selected radio button

From Dev

Disable textInput based on radio button selection on Shiny

From Dev

Disable a Radio button based on label text portion

From Dev

Shiny - How to Style a Selected Radio Buttons Label?

From Dev

how to make radio buttons selected in angularjs

From Dev

How to disable group of radio buttons in java

From Dev

How to disable a radio button if another button is unchecked

Related Related

  1. 1

    How to swap the displayed image based on which radio button is selected?

  2. 2

    How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery)

  3. 3

    How to check if radio buttons are selected on button click?

  4. 4

    How to know which radio button is selected in jquery?

  5. 5

    How to show set of Radio buttons based on a previous Radio Button

  6. 6

    How to show set of Radio buttons based on a previous Radio Button

  7. 7

    how to know which radio button id selected of which row?

  8. 8

    Disable submit button until one in a group of dynamically-created radio buttons selected

  9. 9

    Disable submit button until one in a group of dynamically-created radio buttons selected

  10. 10

    How can I know which radio button is selected via jQuery?

  11. 11

    How to find out which radio button the user selected in Javascript?

  12. 12

    How to check which radio button is selected if they're all runat server?

  13. 13

    How to retrieve which radio button within a LI is selected

  14. 14

    how to know which radio button is selected out of all options?

  15. 15

    How to check which radio button is selected if they're all runat server?

  16. 16

    How to toggle enable/disable input field based on radio button

  17. 17

    Disable text area if radio button is selected?

  18. 18

    Disable text area if radio button is selected?

  19. 19

    jQuery selected radio button index among different sets of radio buttons

  20. 20

    Having some trouble getting which radio button is selected and issuing a command based on the selection

  21. 21

    How to style selected radio button

  22. 22

    How to post selected values from multiple group of radio buttons which generated dynamically

  23. 23

    Show a dropdown based on proper selected radio button

  24. 24

    Disable textInput based on radio button selection on Shiny

  25. 25

    Disable a Radio button based on label text portion

  26. 26

    Shiny - How to Style a Selected Radio Buttons Label?

  27. 27

    how to make radio buttons selected in angularjs

  28. 28

    How to disable group of radio buttons in java

  29. 29

    How to disable a radio button if another button is unchecked

HotTag

Archive