How to get the "value" of a FilteringSelect <select> in dojo?

mctom987 picture mctom987 · Dec 4, 2009 · Viewed 31.1k times · Source

I am using dijit.form.FilteringSelect to provide a way to select values from a <select>. The problem is, when using dojo, the label is returned instead of the value of the s.

For example:
<select name="test" dojoType="dijit.form.FilteringSelect">
<option value="1">One</option>
<option value="2">Two</option>
</select>

Dojo is returning the literal "one" if that option is selected, instead of the value for that option, "1". The same is true for "two" and "2".

If dojo is removed from this element, the value is returned as expected.

Answer

Derek Swingley picture Derek Swingley · Dec 5, 2009

The dojo way to do this would be to use dijit.byId('yourDijitId').attr().

To get the value you want:

dijit.byId('yourDijitId').attr('value');

To get the value displayed in the filtering select:

dijit.byId('yourDijitId').attr('displayedValue');

EDIT: attr() was deprecated at 1.5, at 1.5 and beyond, use get()