PDA

View Full Version : Select - Get the selected text



Flipfine
2 Feb 2012, 1:56 AM
Hi all,

I have a select field.

var select = new Ext.form.Select({
id:'bla',
name:'bla',
label:'blub',
options: [
{text: 'red', value: '1'},
{text: 'blue', value: '2'},
]
});

If I choose e.g blue in the selectfield it appears blue okay...
Now I have a button if I click I would have the text of the option also blue.
But if i do getValue() I get 2 not the text.

Perhaps you could help me

Sameer Khan
2 Feb 2012, 2:35 AM
Your select box creation code should be in the panel...but not individually..


Ext.getCmp('bla').store.findRecord("value", Ext.getCmp('bla').getValue()).get("text");


It will work sure.

Flipfine
2 Feb 2012, 2:52 AM
Thank you for your help Sameer :)

Sameer Khan
2 Feb 2012, 3:06 AM
Your code is this right in the form panel:
---------------------------------


select = new Ext.form.Select({
id:'bla',
name:'bla',
label:'blub',
options: [
{text: 'red', value: '1'},
{text: 'blue', value: '2'},
]
});
Now with safari web inspector you type this "select.store.data", you will have store here..bcz you added 2 elements to select box with options config...so it will be treated as a store for select field...


Right now i under stood with ur code is : you r going to add a record into sqlite Table[#name] with click of button...


your code :
---------------
var addToListButton = new Ext.Button({
cls:'addToListBtn',
text: 'Add to List',
handler:function(){
TimeStore.add({
Blub: Ext.getCmp('bla').store.findRecord("value", Ext.getCmp('bla').getValue()).get("text"),
Blaa: selectB.getValue(),
Datum : datePicker.getValue(),
Dauer: dauer.getValue(),
Kommentar: kommentar.getValue()})
}
});


Try this...

Flipfine
2 Feb 2012, 3:38 AM
yes this work great :)