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

Anan Srivastava

Below is my logic to check the value of each of the radio buttons. I am using a part of their id's to get hold of the radio buttons. However, my code is always returning a value based on the value of my first radio button. I want it to return the value of each radio button. For example if radio button clicked is yes, then value returned should be 1. Else, 0. Any body who can update my code please.

$('.YesNoRadio').each(function() {

    if ($('[id*="YesNo_RadioButtonList_"] input[type="radio"]:checked').val() == 1) {
        //$('[id*="AddAttachment"]').trigger('click');
        $('[id="upload"]').click();
    }

});

Html:

//For yes radio button
<input id="_YesNo_RadioButtonList_0" type="radio" name="YesNo_RadioButtonList" value="1">
//For no
<input id="_YesNo_RadioButtonList_0" type="radio" name="YesNo_RadioButtonList" value="0">
Satpal

Your selector is incorrect, Remove space from selector. When you use " " it indicates you are targeting child elements i.e. Descendant Selector (“ancestor descendant”)

if($('[id*="YesNo_RadioButtonList_"]:radio:checked').val() == 1)
   $('[id="upload"]').click();

And, You don't need .each()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery check value of multiple radio buttons

From Dev

jQuery .val() doesn't work for radio buttons

From Dev

JQuery - check if all radio buttons are "No"

From Dev

How to check the multiple indicdual radio buttons in jQuery?

From Dev

jquery get value of group of radio buttons

From Dev

jquery get value of group of radio buttons

From Dev

Check if radio buttons are set

From Dev

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

From Dev

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

From Dev

jquery check radio button with certain value

From Dev

Getting the value of "on" for 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

From Dev

jQuery For loop with radio buttons

From Dev

jQuery recognising incorrect state of radio buttons on page load when radio value="No" and neither radio is selected

From Dev

Changing value attribute of radio buttons in a group using jQuery

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

Check radio buttons in a loop with a delay

From Dev

TreeView with check boxes and radio buttons

From Dev

Set radio buttons by value using jquery on non-checkboxradio object (buttons behave differently with css)

From Dev

Switch & Case function with Radio Buttons

From Dev

Array not receiving radio buttons value

From Dev

Introducing a value in javascript to radio buttons

From Dev

jquery event listener for radio buttons

From Dev

jquery validation rules for radio buttons

From Dev

FlatUI - radio buttons jQuery compatibility

From Dev

jQuery: Radio buttons not getting checked

Related Related

  1. 1

    jQuery check value of multiple radio buttons

  2. 2

    jQuery .val() doesn't work for radio buttons

  3. 3

    JQuery - check if all radio buttons are "No"

  4. 4

    How to check the multiple indicdual radio buttons in jQuery?

  5. 5

    jquery get value of group of radio buttons

  6. 6

    jquery get value of group of radio buttons

  7. 7

    Check if radio buttons are set

  8. 8

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

  9. 9

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

  10. 10

    jquery check radio button with certain value

  11. 11

    Getting the value of "on" for radio buttons

  12. 12

    Toggling Radio Buttons with jQuery

  13. 13

    jquery radio buttons conflict

  14. 14

    Adding radio buttons with jquery

  15. 15

    radio_buttons with jquery

  16. 16

    jQuery For loop with radio buttons

  17. 17

    jQuery recognising incorrect state of radio buttons on page load when radio value="No" and neither radio is selected

  18. 18

    Changing value attribute of radio buttons in a group using jQuery

  19. 19

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

  20. 20

    Check radio buttons in a loop with a delay

  21. 21

    TreeView with check boxes and radio buttons

  22. 22

    Set radio buttons by value using jquery on non-checkboxradio object (buttons behave differently with css)

  23. 23

    Switch & Case function with Radio Buttons

  24. 24

    Array not receiving radio buttons value

  25. 25

    Introducing a value in javascript to radio buttons

  26. 26

    jquery event listener for radio buttons

  27. 27

    jquery validation rules for radio buttons

  28. 28

    FlatUI - radio buttons jQuery compatibility

  29. 29

    jQuery: Radio buttons not getting checked

HotTag

Archive