Enabling and Disabling Radio Buttons with js

radio button checked javascript
javascript select radio button based on value
set radio button checked javascript
enable disable textbox using radio button+javascript
enable/disable textbox using radio button jquery
enable button when radio button is selected javascript
how to check and uncheck single radio button in javascript
uncheck radio button onclick

help! I am making a some of radio buttons to insert into my data base but with the selected value rules may not be selected twice, I have got the js code for but it doesn't work optimally,the problem is if I chosen 1 in price, then I chose 2 in distace then disable follows the second column while disable in the first column disappears.`

<html>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
    $('input:radio').click(function() {

       $('input:radio').removeAttr('disabled');
       if($(this).is(':checked')) {
           var val = $(this).val();

           $('input:radio').each(function() {
               if(val == $(this).val()) {
                   $(this).attr('disabled',true);
               }
           });

           $(this).removeAttr('disabled');
       }
    });
});
</script>
<body>

  <form class="" action="" method="post">


  <table class="table borderless">
    <tr>
      <th>#</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
      <th>4</th>
      <th>5</th>
    </tr>
    <tr>
      <th>Price</th>
      <th><input type="radio" name="price"  value="1"></th>
      <th><input type="radio" name="price"  value="2"></th>
      <th><input type="radio" name="price"  value="3"></th>
      <th><input type="radio" name="price"  value="4"></th>
      <th><input type="radio" name="price"  value="5"></th>
    </tr>
    <tr>
      <th>distance</th>
      <th><input type="radio" name="distance"  value="1"></th>
      <th><input type="radio" name="distance"  value="2"></th>
      <th><input type="radio" name="distance"  value="3"></th>
      <th><input type="radio" name="distance"  value="4"></th>
      <th><input type="radio" name="distance"  value="5"></th>
    </tr>
    <tr>
      <th>facilities</th>
      <th><input type="radio" name="facilities"  value="1"></th>
      <th><input type="radio" name="facilities"  value="2"></th>
      <th><input type="radio" name="facilities"  value="3"></th>
      <th><input type="radio" name="facilities"  value="4"></th>
      <th><input type="radio" name="facilities"  value="5"></th>
    </tr>
    <tr>
      <th>large</th>
      <th><input type="radio" name="large"  value="1"></th>
      <th><input type="radio" name="large"  value="2"></th>
      <th><input type="radio" name="large"  value="3"></th>
      <th><input type="radio" name="large"  value="4"></th>
      <th><input type="radio" name="large"  value="5"></th>
    </tr>
  </table>
  <button type="sumbit" name="submit">Submit</button>
  </form>

</body>
</html>```
[enter image description here][1]`


  [1]: https://i.stack.imgur.com/6QI93.png

Is this what you're trying to achieve? https://jsfiddle.net/4ayLkm6h/1/

What I've done is create a variable to keep track of what the previous value was:

  const values = {};

I use this in the click handler to check "has the value changed for this column?", if it has, is re-enable all the checkboxes for that column(for example value=1):

  if (values[name]) {
    $('input:radio[value="' + values[name] + '"]').attr('disabled', false);
  }

Then I update the values for next time:

  values[name] = val;

Lastly I disable the ones in the current column:

$('input:radio[value="' + val + '"]:not(:checked)').attr('disabled', true);

The first time you click the check:

if (values[name]) {

Will be false, so I don't re-enable anything (because nothing is disabled yet), so this code is only relevant on the second click, to check if we need to re-enable the previous column before we disable the currently clicked column.

Javascript to disable or enable radio buttons, The disabled property sets or returns whether a radio button should be disabled, or not. A disabled element is unusable and un-clickable. Disabled elements are  Check/Uncheck/Disable Radio Buttons with JavaScript There may be occasions when you will need to check, uncheck, or disable radio buttons based on other form entries. The following form demonstrates one such scenario.


I edited your JS to:

$(document).ready(function() {
    $('input:radio').click(function(){
        var btnGroup = "input:radio[value='" + $(this).attr('value') + "']";
    var btnNameGroup = "input:radio[name='" + $(this).attr('name') + "']";
        $(btnGroup).attr('disabled',true);
    $(btnNameGroup).attr('disabled',true);
    });
});

This groups each radio with their corresponding names and values and you can only select one each within each row and each column. While doing so, the disabled attribute does not leave the groups after another radio button is selected. Since you did not state if you wanted to enable the radio button row again after the first click, I left them all disabled after the user selects something the first time. At least that's how I understood your question.

Here's the jsfiddle of what I've described, maybe this is what you are looking for: https://jsfiddle.net/x1c6mpgL/

HTML DOM Input Radio disabled Property, If the Hazardous Items checkbox is checked, standard shipping is selected and the other two options are disabled. JavaScript for the Example. The JavaScript for​  Here, in this example, we have created simple HTML form with some radio buttons and by using jQuery on change() event , we will show, how enable and disable function works . Also, in place of “input[type=radio]” we used “.second” (Class of a group of radio buttons) to enable/disable a group of radio buttons. To Disable a radio option :


Here is something short and "cryptic", using ES6 function syntax.

First I create an array rbv with similar-value-options from all radio button names. This array contains then 5 jquery objects, each one of length=4.

In the click-handler of the radio buttons I then loop through this array and check for the number of checked elements in each column rv.filter(':checked').length. If it is >0 I set the 'disable' attribute for this whole column to true, otherwise to false.

$(function(){
 var rb =$('input:radio'),              // jquery object with all radio buttons
     rbv=$.makeArray($('[name=price]')) // array of jquery objects, one for each column
          .map(p=>rb.filter((i,r)=>r.value===p.value));
// click-event: check each column for number of checked elements and act accordingly
 rb.click(()=>rbv.forEach(rv=>rv.attr('disabled',rv.filter(':checked').length>0)));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="" action="" method="post">


  <table class="table borderless">
    <tr>
      <th>#</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
      <th>4</th>
      <th>5</th>
    </tr>
    <tr>
      <th>Price</th>
      <th><input type="radio" name="price"  value="1"></th>
      <th><input type="radio" name="price"  value="2"></th>
      <th><input type="radio" name="price"  value="3"></th>
      <th><input type="radio" name="price"  value="4"></th>
      <th><input type="radio" name="price"  value="5"></th>
    </tr>
    <tr>
      <th>distance</th>
      <th><input type="radio" name="distance"  value="1"></th>
      <th><input type="radio" name="distance"  value="2"></th>
      <th><input type="radio" name="distance"  value="3"></th>
      <th><input type="radio" name="distance"  value="4"></th>
      <th><input type="radio" name="distance"  value="5"></th>
    </tr>
    <tr>
      <th>facilities</th>
      <th><input type="radio" name="facilities"  value="1"></th>
      <th><input type="radio" name="facilities"  value="2"></th>
      <th><input type="radio" name="facilities"  value="3"></th>
      <th><input type="radio" name="facilities"  value="4"></th>
      <th><input type="radio" name="facilities"  value="5"></th>
    </tr>
    <tr>
      <th>large</th>
      <th><input type="radio" name="large"  value="1"></th>
      <th><input type="radio" name="large"  value="2"></th>
      <th><input type="radio" name="large"  value="3"></th>
      <th><input type="radio" name="large"  value="4"></th>
      <th><input type="radio" name="large"  value="5"></th>
    </tr>
  </table>
  <button type="sumbit" name="submit">Submit</button>
  </form>

Using JavaScript to Select/Deselect/Disable Radio Buttons, Learn how to enable & disable radio buttons in an HTML form by using jQuery. Just click on live demo or follow our codes. Here we have created an HTML form. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Javascript to disable or enable radio buttons


Enable/Disable Radio Button Using jQuery, So, here's a code that has a button to enable radio buttons which have the disabled attribute. Unfortunately, when I click the button that calls the  jQuery UI includes two ways to disable the button() widget: the disabled option allows you to initialize the button in a disabled state, while the disable() method allows you to disable in response to events after the button has been initialized (the enable() method allows you to enable the button in a similar manner).


How to enable disabled radio buttons using javascript?, When the user chooses an item in column 1, I'm using javascript to disable the radio buttons in column 2 and 3. The same functionality for  An ID would work fine here, but if we wanted to disable multiple form elements in the future, we then only need to apply this class to it for the JavaScript to work on those inputs/buttons too. What this code is actually doing, is setting the disabled attribute on the HTML element to disabled, so when this code is executed, the HTML button will


Need help to enable/disable radio buttons with javascript, Format on Save. If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting. Using jQuery has many features, where it allows you to enable and disable the buttons. By the way, today we will show you how to quickly enable or disable the submit button using jQuery. To enable or disable a button with jQuery, we have to use those two methods, attr () and removeAttr ().