PDA

View Full Version : Better way to select HTML option



nagir
7 Apr 2008, 8:37 PM
Hi,

I have a HTML select field with number of options in it and want to select an option by value.
It can be done with poor JavaScript but just curious if there's some helper in Ext for that.

For now I'm doing it this way.


var fontSizeQry = "select[@id='fontSize']/option[@value='" + item.fontSize + "']";
var fontSizeOption = Ext.select(fontSizeQry).first();
if (fontSizeOption)
fontSizeOption.dom.selected = true;
It's probably not the best way but quite short and simple.
Isn't there anything like Element.selectOptionByValue function?

Cheers,
Dmitriy.

Condor
7 Apr 2008, 10:14 PM
Why not use:


Ext.getDom('fontSize').value = String(item.fontSize);

nagir
7 Apr 2008, 10:25 PM
Hi Condor,

Thanks. You're right!
I didn't realise I can select an option by assigning select's value, so I tried to find the option with given value and set its selected property.

Cheers.