How to get the value of checkbox
How to get the value of a check box?
var tb = new Ext.Toolbar();
tb.add({
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'GetChkBoxValue',
checked: true,
handler: function() {
alert(this.getValue())
}
});
Is it possible to get the value of the checkbox outside tb.I have done something like this but it is not firing
Ext.ge开发者_Go百科tCmp('GetChkBoxValue').getValue();
Try out the following code, it should work:
new Ext.Window({
renderTo: Ext.getBody(),
width: 500,
height: 200,
title: 'test window',
items: [{
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'chkid',
checked: true
}]
}).show()
Ext.getCmp('chkid').getValue()
Then play with the checkbox and with getValue() you get its state (checked or not). Happy ExtJS coding!
Here is what worked for me:
var expandAllGroupsCheckbox = Ext.create(
{
xtype: 'checkbox',
boxLabel: 'Expand Groups by Default',
id: 'chkid',
checked: true,
afterRender: function() {
Ext.form.Checkbox.superclass.afterRender.call(this);
alert(this.getValue());// giving true
this.checkChanged();
},
checkChanged: function()
{
var checked = expandAllGroupsCheckbox.getValue();
gv.startCollapsed = !checked;
if ( gv.mainBody )
{
gv.toggleAllGroups( !checked );
}
},
listeners: {
check: {
fn: function(){expandAllGroupsCheckbox.checkChanged()}
}
}
});
And then:
tbar: [
expandAllGroupsCheckbox
,
{
xtype: 'tbbutton',
icon: '/images/icon_list_props.gif',
handler: function() {
ShowPreferencesPage();
}
}
],
Just this:
var cbox = Ext.getCmp('cboxId');
alert(cbox.checked);
精彩评论