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

Mdjon26

I have a form that looks like this enter image description here

Right now, the problem I am having is that the user can select more than 1 radio button. They should only be able to select 1. I have a Javascript function that will go through all the rows and disable the button that was not selected as seen here.

function disableNonSelectedRadioButtons(selectedRadioButton) {
    $('#payer-contract-global-table .clone-target').each(function (i)  {
        var radioName = 'radio' + '-c' + i;
        if (selectedRadioButton != radioName)
            $('#' + radioName).prop("checked", false);
    });
}

This works. But I need to send the correct selectedRadioButton to this function. How can I correctly do that in Javascript?

Currently the HAML looks like this:

   %input.radio-button{:name => "radio-c#{index}", :type => "radio", :id => "radio-c#{index}", :checked => "true"}

Is there some type of code in Javascript that I can do that says that if I click button for radio-c2 it will send that to my function?

DIEGO CARRASCAL

If you encounter that the event is not being triggered, It happens because the DOM element are being generated dynamically (I think...) I solve it like this:

$(document).on('click', 'input[type="radio"]', function(e){
   var selectedRadioName = $(this).attr('name');
   disableNonSelectedRadioButtons(selectedRadioName);
});

just in case.

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 find out which radio button chosen by the user

From Dev

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

From Dev

How to know which radio button is selected in jquery?

From Dev

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

From Java

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

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 check which radio button is selected if they're all runat server?

From Dev

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

From Dev

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

From Dev

Way to find out which button the user selected on the UIAlertView displayed by iOS ,asking permission to allow the app to receive push notification

From Dev

How to find out which package a user belongs to?

From Dev

JavaScript - Checking if 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

Get value of selected radio button which is saved in Firebase, and set it as default state in user profile

From Dev

How to style selected radio button

From Dev

How to know which button the user selected on <paper-dialog>?

From Dev

How to know which button the user selected on <paper-dialog>?

From Java

Find out whether radio button is checked with JQuery?

From Dev

prob with selected radio button using javascript?

From Dev

JavaScript validation to check if a radio button is selected?

From Dev

Get selected radio button value in javascript

From Dev

How can I tell which radio button is selected with node.js

From Dev

How to get list of values which are selected in radio button after click on submit in Angular js

From Java

How to find out which microphone device user gave permission to?

From Dev

How can I find out which user deleted a directory?

From Dev

how to check if input field has filled out and radio button has been selected

From Dev

How do I get the value of a user-selected radio button in the controller?

From Dev

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

Related Related

  1. 1

    How to find out which radio button chosen by the user

  2. 2

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

  3. 3

    How to know which radio button is selected in jquery?

  4. 4

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

  5. 5

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

  6. 6

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

  7. 7

    How to retrieve which radio button within a LI is selected

  8. 8

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

  9. 9

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

  10. 10

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

  11. 11

    Way to find out which button the user selected on the UIAlertView displayed by iOS ,asking permission to allow the app to receive push notification

  12. 12

    How to find out which package a user belongs to?

  13. 13

    JavaScript - Checking if Radio Button is selected

  14. 14

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

  15. 15

    Get value of selected radio button which is saved in Firebase, and set it as default state in user profile

  16. 16

    How to style selected radio button

  17. 17

    How to know which button the user selected on <paper-dialog>?

  18. 18

    How to know which button the user selected on <paper-dialog>?

  19. 19

    Find out whether radio button is checked with JQuery?

  20. 20

    prob with selected radio button using javascript?

  21. 21

    JavaScript validation to check if a radio button is selected?

  22. 22

    Get selected radio button value in javascript

  23. 23

    How can I tell which radio button is selected with node.js

  24. 24

    How to get list of values which are selected in radio button after click on submit in Angular js

  25. 25

    How to find out which microphone device user gave permission to?

  26. 26

    How can I find out which user deleted a directory?

  27. 27

    how to check if input field has filled out and radio button has been selected

  28. 28

    How do I get the value of a user-selected radio button in the controller?

  29. 29

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

HotTag

Archive