views:

862

answers:

2

I am using dijit.form.FilteringSelect to provide a way to select values from a . 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.

+1  A: 

I have found out that dojo creates 2 elements. One using the name, which contains the value which uses the NAME of the element, and another which contains the label for the option, which uses the ID of the element. Since I was using document.getElementById(), this was returning the wrong value. Using the value from the name provides the correct result.

+3  A: 

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');
Swingley