travelModeString =
document.getElementById('mode').options[document.getElementById('mode').selectedIndex].value;
<select id="mode" name="mode" style="width:70px">
<option value="WALKING">Walking</option>
<option value="DRIVING">Driving</option>
</select>
Does not work.
travelModeString =
document.getElementById('mode').options[document.getElementById('mode').selectedIndex].value;
<select id="mode" name="mode" style="width:70px">
<option value="G_TRAVEL_MODE_WALKING">Walking</option>
<option value="G_TRAVEL_MODE_DRIVING">Driving</option>
</select>
This too does not work.
On Apr 27, 7:06 am, JKurtock <[email protected]> wrote:
> With a SELECT box, what you want is the VALUE of member of a
> COLLECTION of options, which MEMBER is indexed from the collection by
> the selectedIndex.
>
> Take a look athttp://msdn.microsoft.com/en-us/library/ms537472(v=VS.85).aspx
>
> So as I said, what you want is
> travelModeString =
> document.getElementById('mode').options[document.getElementById('mode').selectedIndex].value;
>
> But be alert to the issue raised by Esa; travelModeString is a string
> (with the value of either "WALKING" or "DRIVING". It is only good
> luck that those strings correspond to the string value of
> google.maps.TravelMode.WALKING and google.maps.TravelMode.DRIVING.
> But they will work.
>
> They method suggested by Esa (using the selected index to index into
> your own array of google.maps constants, and forget about the value of
> the options) is more robust but a little clunkier.
>
> - Jeff
>
> On Apr 27, 5:20 am, summerap <[email protected]> wrote:
>
>
>
> > but how i assign element of array into option to let user choose?
> > there must be an interface to allow user choose right? Any suggestion?
>
> > On Apr 27, 4:58 am, Esa <[email protected]> wrote:
>
> > > The first one probably works
>
> > > <select id="mode" style="width:70px">
> > > <option value="WALKING">Walking</option>
> > > <option value="DRIVING">Driving</option>
> > > </select>
>
> > > but that is just good luck because those happen to be string values of
> > > constants
>
> > > google.maps.TravelMode.WALKING and
> > > google.maps.TravelMode.DRIVING
>
> > > Put those constants in an array and let the select element choose from
> > > the array
>
> > > var modeArray = [];
> > > modeArray[0] = google.maps.TravelMode.WALKING;
> > > modeArray[0] = google.maps.TravelMode.DRIVING;
>
> > > var selectedMode =
> > > modeArray[document.getElementById("mode").selectedIndex];
>
> > > Don't set values of select element at all. As Jeff said, they are not
> > > very useful. Some browsers return a selected value but not all. That
> > > is because of different 'multiple' attribute handling. It is better to
> > > keep the values in a separate array.
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.