We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to get the value?

When selecting a radio button I want to retrieve the value associated with it- - is this possible?

5 Replies

SD Saranya Dhayalan Syncfusion Team January 20, 2020 07:35 AM UTC

Hi Alex,  
  
Thanks for contacting Syncfusion support.  
  
We have checked your requirement and we have an API ‘getSelectedValue’ which is used for getting the selected value from the group of radio buttons. You can use this method in any one of the radio button instances in the group. Please find the below code snippet: 
 
@using Syncfusion.EJ2.Blazor.Buttons 
 
<EjsRadioButton @ref="radiobtn" Label="Option 1" Name="options" Value="option1"></EjsRadioButton> 
<EjsRadioButton Label="Option 2" Name="options" Value="option2" Checked="true"></EjsRadioButton> 
 
<button @onclick="@getSelectedValue">Get Value</button> 
 
@code{ 
    EjsRadioButton radiobtn; 
 
    public async void getSelectedValue() 
    { 
        string obj = await radiobtn.GetSelectedValue(); 
    } 
} 
 
 
 
Please find the below API documentation link: 
 
Could you please check the above code snippet and get back to us if you need further assistance on this?  
 
Regards,  
Saranya D 
 



AL Alex February 3, 2020 08:33 AM UTC

Hi, thanks for the response.

How do we do this without using a button?  I want to be able to get the value after selecting a radio button not by then pressing a button.


SD Saranya Dhayalan Syncfusion Team February 4, 2020 05:17 AM UTC

Hi Alex 
 
Thanks for the update 
 
Query: How do we do this without using a button?  I want to be able to get the value after selecting a radio button not by then pressing a button. 
 
We have checked your reported query, we can get the value after selection radiobutton in OnChange event. Please find the below code snippet: 
 
@using Syncfusion.EJ2.Blazor.Buttons 
 
<EjsRadioButton @ref="radiobtn1" Label="Option 1" Name="options" Value="option1" OnChange="onChange"> 
</EjsRadioButton> 
<EjsRadioButton @ref="radiobtn2" Label="Option 2" Name="options" Value="option2" Checked="true" OnChange="onChange1"></EjsRadioButton> 
 
@code{ 
    EjsRadioButton radiobtn1; 
 
    EjsRadioButton radiobtn2; 
 
    public async void onChange() 
    { 
        string obj = await radiobtn1.GetSelectedValue(); 
    } 
     public async void onChange1() 
    { 
        string obj1 = await radiobtn2.GetSelectedValue(); 
    } 
} 
 
 
Please find the below API doc link 
 
 
Could you please check the above code snippet and get back to us if you need further assistance on this? 
 
Regards, 
Saranya D 



AL Alex February 4, 2020 02:02 PM UTC

Thanks for the response.

Can we have a single method and then detect the value of the radio button that fired the method off?


SD Saranya Dhayalan Syncfusion Team February 5, 2020 05:37 AM UTC

Hi Alex, 
 
Good day to you 
 
Query: Can we have a single method and then detect the value of the radio button that fired the method off? 
 
We have checked your reported scenario, If you want to use a single method in the radio button group, you need to bind the change event to each radio button. Please find the below code snippet 
 
@using Syncfusion.EJ2.Blazor.Buttons 
 
<EjsRadioButton @ref="radiobtn" Label="Option 1" Name="options" Value="option1" OnChange="onChange"> 
</EjsRadioButton> 
<EjsRadioButton Label="Option 2" Name="options" Value="option2"  OnChange="onChange"></EjsRadioButton> 
 
@code{ 
    EjsRadioButton radiobtn; 
 
    public async void onChange() 
    { 
        string obj = await radiobtn.GetSelectedValue(); 
    } 
} 
 
 
 
Could you please check the above code snippet and get back to us if you need further assistance on this? 
 
Regards, 
Saranya D 


Loader.
Live Chat Icon For mobile
Up arrow icon