User will not be able to select a button that is already selected

The button group does not work as it should, the problem is that the ON option is selected , it should not be selected again, but the problem is that the ON button is selected I can select the ON button again.

How can I stop my button to stop the action when the button is already selected.

This is my code for my button group ---

<form action="myclass.php" method="post">
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-default btn-xs myOnbutton">
            // myOnbutton is the button name
            <input type="radio" autocomplete="off"> ON
        </label>
        <label class="btn btn-default btn-xs myOffbutton">
            // myOffbutton is the button name
            <input type="radio" autocomplete="off"> OFF
        </label>
    </div>
</form>

      

Does anyone know where I am making the mistake, so it selects the button again.

Thanks for the advanced one.

+3


source to share


2 answers


if you want to disable groups after the first selection you have to use jquery like Plunker :

 $(".btn-xs :radio").click(function(){
  $(".btn-xs :radio").attr("disabled", true); //Disable all with the same name
});

      



and if you only want to disable the selected radio button Plunker :

$(".btn-xs :radio").click(function(){
  $(this).attr("disabled", true); //Disable all with the same name
});

      

0


source


This is basic HTML. It has nothing to do with loading, you just need to add names to the checkboxes so you can't select both.



<label class="btn btn-default btn-xs myOnbutton">
    <input type="radio" autocomplete="off" name="switch"> ON
  </label>
  <label class="btn btn-default btn-xs myOffbutton">
    <input type="radio" autocomplete="off" name="switch"> OFF
  </label>

      

0


source







All Articles