Get values from RadioButton

2 Answers 3294 Views
Button
Ram
Top achievements
Rank 1
Ram asked on 07 Feb 2017, 09:46 AM

Hi all

I saw this demo  :  http://demos.telerik.com/aspnet-mvc/styling/radios

I want to know which radiobutton that user checked in client side.

for this one

@(Html.Kendo().RadioButton().Name("engine1").Checked(true).HtmlAttributes(new{@name = "engine"}).Label("1.4 Petrol, 92kW"));

I'm trying to use this

var rbEngine = $("#engine1").data("kendoRadioButton");

but I can't get any value...even checking status...

Am I using wrong method?  

Thanks

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Eduardo Serra
Telerik team
answered on 07 Feb 2017, 03:59 PM
Hello Ram,

You can try the following:

if ($("[name='engine1']").is(":checked"))

I hope this helps!

Regards,
Eduardo Serra
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Ram
Top achievements
Rank 1
commented on 08 Feb 2017, 12:50 AM

Hi : Eduardo Serra thank you!
I get the checked status by using  
$("[name='engine']").is(":checked")   
but
If there are two Radiobuttin existing like this
    @(Html.Kendo().RadioButton().Name("engine1").Checked(true).HtmlAttributes(new { @name = "engine" }).Label("1.4 Petrol, 92kW"));
    @(Html.Kendo().RadioButton().Name("engine2").HtmlAttributes(new { @name = "engine" }).Label("1.8 Petrol, 118kW"));
always get True value in this situation.

Finally I'm using     $("[id='engine1_']").is(":checked")
I don't know where is the '_' char from, in HTML like this
<input checked="checked" class="k-radio" id="engine1_" name="engine" type="radio" value="">
<input class="k-radio" id="engine2_" name="engine" type="radio" value="">

Thank you agin, Eduardo Serra.

Veselin Tsvetanov
Telerik team
commented on 09 Feb 2017, 03:22 PM

Hello Ram,

I am happy to learn that you have successfully implemented the desired check.

Normally, the rendered input elements for the Kendo widgets have both the Name and the Id attributes set to the same value. In the discussed scenario, the underscore is automatically appended to the id of the input to signify the fact that the two values are different.

Regards,
Veselin Tsvetanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Aziz
Top achievements
Rank 1
Veteran
commented on 03 Feb 2021, 08:13 AM

 @(Html.Kendo().RadioButton().Name("radiobutton_legal").Checked(true).HtmlAttributes(new { @name = "search_type" }).Label("Физлицо"))
                 &nbsp;&nbsp;
                 @(Html.Kendo().RadioButton().Name("radiobutton_entity").Checked(false).HtmlAttributes(new { @name = "search_type" }).Label("Юрлицо"))
                 &nbsp;&nbsp;
                 @(Html.Kendo().RadioButton().Name("radiobutton_cooperative").Checked(false).HtmlAttributes(new { @name = "search_type" }).Label("ЖСК"))

-----

function addAddressData() {
        var search_type = 0;
        if ($("#radiobutton_legal").prop('checked')) {
            search_type = 1
        } else if ($("#radiobutton_entity").prop('checked')) {
            search_type = 2
        }
        else if ($("#radiobutton_cooperative").prop('checked')) {
            search_type = 3
        }
        return {
            keyword: $("#autocomplete_address").val(),
            search_type: search_type
        }
    }

Acadia
Top achievements
Rank 1
Iron
commented on 17 Jul 2023, 06:26 PM

I found @Aziz answer to be simple and it worked perfectly.  Eduardo's solution did not work for me.  The "val()" was a long nasty alphanumeric value.
0
Veselin Tsvetanov
Telerik team
answered on 03 Feb 2021, 02:30 PM

Hi Aziz,

Since the R1 2021.1.119 release of Telerik UI for ASP.NET MVC, the suite features a brand new RadioGroup HTML helper. I believe that would be a great fit for the scenario in question.

Regards,
Veselin Tsvetanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Button
Asked by
Ram
Top achievements
Rank 1
Answers by
Eduardo Serra
Telerik team
Veselin Tsvetanov
Telerik team
Share this question
or