tags:

views:

58

answers:

3

Here's my attempt to get the last item in the dropdown and check it:

if (day.lastIndexOf(day.length) == 28) {

..do something

}

day var is set to reference dropdown control. Obviously I am not doing this right. How do I know where I can apply lastIndexOf on a dropdownlist? How do I get at it's array? I tried this also but it doesn't work, syntax error:

day.options.lastIndexOf(day.length)

one would think that should work, options is an array of values I think..has to be.

A: 

Try:

day.options[day.options.length-1]
Roatin Marth
Is `day` pointing to a `<select>` element or not?
Roatin Marth
I did not have .value.
CoffeeAddict
If so, `day.options[day.options.length-1].value` should work fine.
Roatin Marth
wtf dude. Come on.
Roatin Marth
@Roatin: Let it go. The `value` part was important and your solution didn't have it.
Tim Down
A: 

coffeeaddict,

The lastIndexOf() method returns the position of the last occurrence of a specified string value, searching backwards from the specified position in a string.

You're probably trying to do this:

if (day.options[day.options.length-1].value == 28) {
...
}
Daniel
A: 
var o = day.options;
var option = o[o.length - 1];

Note that option is an Option object with text and value properties that you can use for your checks.

Tim Down