Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a radiobutton change

I have about 50 radiobuttons on one form and I don't want to create an if statement for each one to detect when one changes, they are not part of a group box. How would I detect if any radiobutton changed and then write the name to another variable?

like image 655
Henry Penton Avatar asked Jan 13 '23 21:01

Henry Penton


1 Answers

Put all the radio buttons on a panel and loop through the panels radio button controls, programmatically adding the same event handler for each as described by @Steve. One way I like to handle the event is to assign each radio button an index into its tag property. Then just store any relevant data in a list of objects and access the data for that radio button by pulling out it's corresponding object from the list using its tag. Much easier than doing it by hand.

Edit: Good catch @Neolisk. Updated answer.

like image 103
Davido Avatar answered Jan 31 '23 00:01

Davido