Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of Radio Buttons?

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

like image 747
salman Avatar asked Nov 24 '12 06:11

salman


People also ask

Can radio button have value?

Radio buttons don't participate in constraint validation; they have no real value to be constrained.

How do I find the value of a radio group?

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.

How do I get the value of a radio button in react?

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'} .

How do I get the value of a radio button in Python?

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.


1 Answers

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();
like image 190
sajanyamaha Avatar answered Sep 23 '22 04:09

sajanyamaha