Pari
Pari

Reputation: 339

How to get radiogroup checked value using extjs 4?

I am using extjs 4 for radio buttons. Code is as follow

var mychkbxgrp = Ext.create('Ext.form.RadioGroup',{
    fieldLabel: 'Layer',
    columns: 1, 
    items:[{
     boxLabel: 'District', name: 'rb', inputValue: 'district',itemId:"DIS"
    },{
     boxLabel: 'SubDistrict', name: 'rb', inputValue: 'Subdistrict',itemId:"sub"
    },{
     boxLabel: 'Village', name: 'rb', inputValue: 'Village'
    },{
     boxLabel: 'Road', name: 'rb', inputValue: 'Roads'
    },{
     boxLabel: 'Point', name: 'rb', inputValue: 'POINT'
    }],
    listeners: {
     change : function(){ 
         alert(this.getValue());
        }
    }
    });

I want to get the value of checked radio button once its checked. for that i have used listeners but not working. Am i right or need to use other way. please help me for same.

Upvotes: 3

Views: 17974

Answers (4)

TriumphST
TriumphST

Reputation: 1214

This could also be written generically to handle all your radio groups. Value (used radioGroup in my example) is the RadioGroup, so you can use

getChecked()
like so:

listeners: {
    change: radioGroupHandler
}

...

function radioGroupHandler(obj, radioGroup) {
    var checked = radioGroup.getChecked();

    if (checked.length) {
         alert(radioGroup.getChecked()[0].getValue());
    } else {
         alert('nothing checked');
    }
}

Upvotes: 0

Renganathan M G
Renganathan M G

Reputation: 5209

You can use the function getChecked()

Upvotes: 3

Raza Ahmed
Raza Ahmed

Reputation: 2751

I've tried many solutions, and following one worked only. Hope it helps

listeners: {
     change : function(obj, value){ 
         alert(value.individual);
        }
    }

Upvotes: 2

Jalin Gladis
Jalin Gladis

Reputation: 113

Your code looks good. The change event is getting fired. Only change you have to make is

listeners: {
     change : function(obj, value){ 
         alert(value.rb);
        }
    }

Where value.rb will give you the value of the radio button which got selected.

Upvotes: 2

Related Questions