I have a group box contains radio buttons eg.
o Male
o Female
i want my code to get the selected value of radio button and copy it to string type variable kindly use simple code cause m not very professional
thanks
Radio buttons don't participate in constraint validation; they have no real value to be constrained.
Answer: Use the jQuery :checked selector You can simply use the jQuery :checked selector in combination with the val() method to find the value of the selected radio button inside a group.
To set the default checked value of a radio button in React: Store the radio button value in the state. Initialize the state to the value of the default checked radio button. Set the checked property on each radio button conditionally, e.g. checked={selected === 'yes'} .
The radiobutton has only two values, either True or False. If we want to get the output to check which option the user has selected, then we can use the get() method. It returns the object that is defined as the variable.
For Win Forms :
To get the value (assuming that you want the value, not the text) out of a radio button, you get the Checked property:
string value = "";
bool isChecked = radioButton1.Checked;
if(isChecked )
value=radioButton1.Text;
else
value=radioButton2.Text;
For Web Forms :
<asp:RadioButtonList ID="rdoPriceRange" runat="server" RepeatLayout="Flow">
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
</asp:RadioButtonList>
And CS-in some button click
string value=rdoPriceRange.SelectedItem.Value.ToString();
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