How to get the value of the current SELECT element

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.