PDA

View Full Version : I can't get the value I selected from my combobox ...need help



bbsdgr8
16 Feb 2010, 8:04 AM
Hi,
Here's my code for the combobox


var bank = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
store: new Ext.data.ArrayStore({
id: 'bnk',
hiddenName:'id',
fields: [
'myId',
'displayText'
],
data: [[1, 'dbp'], [2, 'lbp']]
}),
valueField: 'myId',
displayField: 'displayText',
mode: 'local',
emptyText:'Select',
selectOnFocus:true,

});
but I can't get the value of the combobox with a simple alert.

alert(Ext.getCmp("bnk").getValue());

p3p3
16 Feb 2010, 8:11 AM
hi,

set the id property on the right place ;) (the combobox dont have any atm)


var bank = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
id: 'bnk',
store: new Ext.data.ArrayStore({
// id: 'bnk',
hiddenName:'id',
fields: [
'myId',
'displayText'
],
data: [[1, 'dbp'], [2, 'lbp']]
}),
valueField: 'myId',
displayField: 'displayText',
mode: 'local',
emptyText:'Select',
selectOnFocus:true,

});p3p3

dlbjr
16 Feb 2010, 8:33 AM
var ds = new Ext.data.ArrayStore({
fields: ['myId','displayText'],
data: [[1, 'dbp'], [2, 'lbp']]
}),


var cb = new Ext.form.ComboBox({
store: ds,
mode: 'local',
valueField: 'myId',
displayField: 'displayText',
fieldLabel: 'field Label',
triggerAction: 'all',
width: 100,
typeAhead: true,
selectOnFocus: true,
forceSelection: true,
allowBlank: false,
disabled: false,
emptyText:'Select...'
});

alert(cb.getValue());

fay
16 Feb 2010, 8:35 AM
EDIT: Ya just beat me to it @p3p3 :)

As @p3p3 says, you've specified the combo's "id" within the ArrayStore.

Try:


var bank = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
id: 'bnk',
hiddenName:'id',
store: new Ext.data.ArrayStore({
fields: [
'myId',
'displayText'
],
data: [[1, 'dbp'], [2, 'lbp']]
}),
valueField: 'myId',
displayField: 'displayText',
mode: 'local',
emptyText:'Select',
selectOnFocus:true // <-- Watch for extra commas
});

httpdotcom
16 Feb 2010, 9:39 AM
On top of both of those correct answers, is there a reason not to use "bank.getValue()", instead of the overhead necessary for "Ext.getCmp("bnk").getValue()"?