How to check the multiple indicdual radio buttons in jQuery?

user3494837

In my page so many group radio buttons are there like this.

first div "Request-1" only default checked.After button click I am calling the below jQuery function to assign selected value to other div radio buttons.

if ($("#Request-1:input:checked").length > 0) {

            $("#Request-2").attr('checked', 'checked');
            $("#Request-3").attr('checked', 'checked');
            $("#Request-4").attr('checked', 'checked');
        }
        else if ($("#DRequest-1:input:checked").length > 0) {
            $("#DRequest-2").attr('checked', 'checked');
            $("#DRequest-3").attr('checked', 'checked');
            $("#DRequest-4").attr('checked', 'checked');

        }

But only #REquest-4 is checking other radio buttons are not checking .Please tell me how to check all radio buttons .

 <div id="choose-1">
<input id="Request-1"  type="radio" name="request-type"  checked="checked"/>Data REquest



     <input id="DRequest-1"  type="radio" name="request-type"/>D Request Data
    </div>
 <div id="choose-2">
    <input id="Request-2"  type="radio" name="request-type" />Data REquest

      <input id="DRequest-2"  type="radio" name="request-type"/>D Request Data
    </div>
 <div id="choose-3">
    <input id="Request-3"  type="radio" name="request-type" />Data REquest

      <input id="DRequest-13"  type="radio" name="request-type"/>D Request Data
    </div>
 <div id="choose-4">
    <input id="Request-4"  type="radio" name="request-type"  checked="checked"/>Data REquest

      <input id="DRequest-4"  type="radio" name="request-type"/>D Request Data
    </div>
Rohan Kumar

You are using radio buttons and they are in a same group request-type so only one can be selected in this case

To work you need to use checkboxes inplace of radios

Then try to use prop() and merge all selectors separated by a , like

if ($("#Request-1:checked").length > 0) {
   $("#Request-2, #Request-3, #Request-4").prop('checked', true);
}
else if ($("#DRequest-1:checked").length > 0) {
   $("#DRequest-2, #DRequest-3, #DRequest-4").prop('checked', true);
}

Live Demo

If you need to toggle checkboxes on changing their status then try this,

$('#Request-1').on('change',function(){
    $("#Request-2, #Request-3, #Request-4").prop('checked', this.checked);    
}).change();
$('#DRequest-1').on('change',function(){
    $("#DRequest-2, #DRequest-3, #DRequest-4").prop('checked', this.checked);    
}).change();

Checkbox change demo

Again you need to use radios then you need to change radio buttons grouping like,

<div id="choose-1">
    <input id="Request-1" type="radio" name="request-type" checked="checked" />Data REquest
    <input id="DRequest-1" type="radio" name="request-type" />D Request Data</div>
<div id="choose-2">
    <input id="Request-2" type="radio" name="request-type-2" />Data REquest
    <input id="DRequest-2" type="radio" name="request-type-2" />D Request Data</div>
<div id="choose-3">
    <input id="Request-3" type="radio" name="request-type-3" />Data REquest
    <input id="DRequest-3" type="radio" name="request-type-3" />D Request Data</div>
<div id="choose-4">
    <input id="Request-4" type="radio" name="request-type-4" />Data REquest
    <input id="DRequest-4" type="radio" name="request-type-4" />D Request Data
</div>

Radio change demo

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 check the values of multiple dynamic radio buttons in a form using jquery

From Dev

jQuery check value of multiple radio buttons

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

JQuery - check if all radio buttons are "No"

From Dev

How to Validate Multiple radio buttons

From Dev

Jquery .val() function to check the value of radio buttons

From Dev

How to validate radio buttons in jquery?

From Dev

Multiple radio buttons are being checked in JQuery Mobile

From Dev

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

From Dev

How to check radio buttons values and if else..?

From Dev

How to create dynamic radio buttons with multiple options

From Dev

How to have multiple radio buttons with different functionality?

From Dev

How to create dynamic radio buttons with multiple options

From Dev

How to center align multiple radio buttons in FlowLayoutPanel?

From Java

How to check a radio button with jQuery?

From Dev

Check if radio buttons are set

From Dev

jQuery How to auto sync groups of radio buttons

From Dev

How to filter elements in jQuery using radio buttons

From Dev

How to filter elements in jQuery using radio buttons

From Dev

How to get the radio buttons that are NOT checked (Jquery)?

From Dev

how to clear the radio buttons using check box un check

From Dev

How do I record answers from multiple different radio buttons in a survey using jQuery?

From Dev

jQuery: how to re-use same function for multiple sets of radio buttons

From Dev

Using jQuery to check if one in set of radio buttons is checked

From Dev

Handling multiple radio buttons

From Dev

Toggling Radio Buttons with jQuery

From Dev

jquery radio buttons conflict

From Dev

Adding radio buttons with jquery

From Dev

radio_buttons with jquery

Related Related

  1. 1

    How to check the values of multiple dynamic radio buttons in a form using jquery

  2. 2

    jQuery check value of multiple radio buttons

  3. 3

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

  4. 4

    JQuery - check if all radio buttons are "No"

  5. 5

    How to Validate Multiple radio buttons

  6. 6

    Jquery .val() function to check the value of radio buttons

  7. 7

    How to validate radio buttons in jquery?

  8. 8

    Multiple radio buttons are being checked in JQuery Mobile

  9. 9

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

  10. 10

    How to check radio buttons values and if else..?

  11. 11

    How to create dynamic radio buttons with multiple options

  12. 12

    How to have multiple radio buttons with different functionality?

  13. 13

    How to create dynamic radio buttons with multiple options

  14. 14

    How to center align multiple radio buttons in FlowLayoutPanel?

  15. 15

    How to check a radio button with jQuery?

  16. 16

    Check if radio buttons are set

  17. 17

    jQuery How to auto sync groups of radio buttons

  18. 18

    How to filter elements in jQuery using radio buttons

  19. 19

    How to filter elements in jQuery using radio buttons

  20. 20

    How to get the radio buttons that are NOT checked (Jquery)?

  21. 21

    how to clear the radio buttons using check box un check

  22. 22

    How do I record answers from multiple different radio buttons in a survey using jQuery?

  23. 23

    jQuery: how to re-use same function for multiple sets of radio buttons

  24. 24

    Using jQuery to check if one in set of radio buttons is checked

  25. 25

    Handling multiple radio buttons

  26. 26

    Toggling Radio Buttons with jQuery

  27. 27

    jquery radio buttons conflict

  28. 28

    Adding radio buttons with jquery

  29. 29

    radio_buttons with jquery

HotTag

Archive