Link to home
Start Free TrialLog in
Avatar of Michael Lam
Michael Lam

asked on

How to check if you are clicking on a radio buttons that's already selected

I have several rows of twin radio buttons that are generated via a loop in ruby on rails.  For each row, one of the button is already selected, how do i detect if the user accidentally click on a radio button that's already selected?  Keep in mind these buttons all have generated ids so I can just look for a specific id.  Can someone show me how to do this via ruby on rails or javascript?  Thanks.
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

You can handle both click and change events for radio buttons.

https://jsfiddle.net/ta17qkeq/
This is not a helpful answer:

Why do you need to know if someone clicks on a selected radio button?
Avatar of Michael Lam
Michael Lam

ASKER

I need to know that so when the user clicks on a radio button that's already selected, I can ignore it.  Otherwise it will considered that a change and make a call to the backend to update the "change".  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Moussa Mokhtari
Moussa Mokhtari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately this doesn't work for IE8,9,10 due to the change event bug on IE.  So I have to use onClick event.
I have no access to IE on my systems. I'll have to leave it for someone else to answer.