29793

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.getCmp('GetChkBoxValue').getValue();

Answer1:

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!

Answer2:

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(); } } ],

Answer3:

Just this:

var cbox = Ext.getCmp('cboxId'); alert(cbox.checked);

Recommend

  • Watir webdriver and extjs finding element
  • How to use addCls() in extjs 3.2
  • Using responsive plugin in ExtJS 5
  • Ext JS 4: Grid List Filter is NOT updated
  • JavaFX TableView click sorters not working?
  • Get current day's steps during datapointListener google Fit
  • How to prevent TreeItem selection?
  • Android onKey w/ virtual keyboard
  • WPF Template Binding in ToggleButton UserControl
  • blade.php method outputting it's result to the form
  • Floated image with variable width and heading with background image
  • Can't delete or rename original file after resizing
  • D3 get axis values on zoom event
  • How to use JavaScript to determine whether a file exists in a directory?
  • Detect when Facebook like button is clicked
  • AJAX Html Editor Extender upload image appearing blank
  • Functions in global context
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • FileReader+canvas image loading problem
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?
  • To display the title for the current loaction in map in iphone
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Compare two NSDates in iPhone
  • Comma separated Values
  • trying to dynamically update Highchart column chart but series undefined
  • Acquiring multiple attributes from .xml file in c#
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • How can I remove ASP.NET Designer.cs files?
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • java string with new operator and a literal
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?