How to get the value of the current SELECT element
var getselectvalue = function (select)
{
var idx = Select.selectedindex,
Option
Value
if (idx >-1) {
option = Select.options[idx];
value = Option.attributes.value;
Return (value && value.specified)? Option.value:option.text;
}
return null;
}
If all option elements under the SELECT element do not specify the selected property, the first is selected by default. The
can get the index of the selected option element through Select.selectedindex. The
can be obtained through Select.options[select.selectedindex] to the selected option element.
Option Element <option selected= "selected" value= "Value3" >text3</option>, which can be obtained by option.value Value property, that is, value3; you can get the text within the option element by Option.text, that is, Text3.
If the option element does not have a value attribute defined, then option.value in IE cannot be obtained, but Safari, opera, and Firefox can still be obtained through option.value, with a value of option.text. The
Option.attributes.value && option.attributes.value.specified can be used to determine whether the option element defines the Value property.