The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Bob C. (6) [Avatar] Offline
#1
I'm trying to get the value of a check box when a button is clicked. When the user clicks a button, I open a dialog, which I set up with the onReady event. Based on the value of the checkbox, checked or unchecked, I will take a certain action. But I have been unable to get the checkbox value. I've tried this:

var chk = Ext.get('mycheckbox');
chk.getValue();

But this always return true, whether the checkbox is checked or not. I've also tried chk.checked, but that doesn't work either. Can someone put me on the right track?

Thanks very much,
Bob
jesus.garcia (463) [Avatar] Offline
#2
Re: Get value of checkbox - checked or not checked
Try Ext.getCmp
Bob C. (6) [Avatar] Offline
#3
Re: Get value of checkbox - checked or not checked
something like this?

var mycheckbox = Ext.getCmp('mychkbox').getValue();
This returns 'undefined' whether checkbox is checked or not

I should note that this is not an 'Ext' checkbox, but rather a standard html checkbox.
jesus.garcia (463) [Avatar] Offline
#4
Re: Get value of checkbox - checked or not checked
Does the checkbox have that id configured?
Bob C. (6) [Avatar] Offline
#5
Re: Get value of checkbox - checked or not checked
Yes

<input type="checkbox" name="mychkbox" id="mychebox" maxlength="1" size="1">

This is how I would check with JQuery:

var checked = $('input[type=checkbox]').is(':checked');
(if i only have one checkbox on the form)
Bob C. (6) [Avatar] Offline
#6
Re: Get value of checkbox - checked or not checked
I got it working by making a call to another function and using jQuery to get the value. I'm just starting out with Ext, so I still don't have much insight into it yet, but it looks great. By the way, I bought the early access edition of Ext JS in Action, and just started reading it. Very nicely written.

Thanks for your help,
Bob
jesus.garcia (463) [Avatar] Offline
#7
Re: Get value of checkbox - checked or not checked
GetCmp will return an instance of an extjs component. Ext.get returns an ext.element wrapped Dom element.

In the extjs world, we generally abstract out Dom-level calls and use the framework.