I have these groupboxes:
I want to run some code according to checked true state of a radio button like:
string chk = radiobutton.nme; // Name of radio button whose checked is true switch(chk) { case "Option1": // Some code break; case "Option2": // Some code break; case "Option3": // Some code break; }
Is there any direct way so that I can only get the name of the checked radio button?
To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.
The Checked property of the radio button is used to set the state of a radio button. You can display text, image or both on radio button control. You can also change the appearance of the radio button control by using the Appearance property.
Get the value of selected radio button: querySelector() Remember you need to specify the name property of the radio button in HTML code. It is used as document. querySelector('input[name="JTP"]:checked') inside the <script> tab to check the selected radio button value from the group of radio buttons.
Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.
You can find all checked RadioButtons like
var buttons = this.Controls.OfType<RadioButton>() .FirstOrDefault(n => n.Checked);
Also take a look at CheckedChanged
event.
Occurs when the value of the Checked property changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With