Method for JavaScript to get the value and text value of select dropdown box option

Source: Internet
Author: User

JS get Select drop-down box the value value of each option is relatively easy, but getting the text value is a bit of a hassle, for a beginner JavaScript novice, may not be able to find a moment, then please look at the method of this article, Take the Select drop-down box menu in a form form as an example of how to get its value and text values in javascript:

Sample form, which is a select drop-down list box with individual list items and values:

<formname= "Form1"><Selectname= "TestValue"><optionvalue= "ASP">Asp</option><optionvalue= "PHP">Php</option><optionvalue= "JSP">Jsp</option></Select></form>

Next is the JavaScript section, which gets the individual value and text values for select:

// gets the value of the Select drop-down box option: Document.form1.testvalue.value // gets the text value of the Select drop-down box option:Document.form1.testvalue.options[document.form1.testvalue.selectedindex]. Text

Method for JavaScript to get the value and text value of select dropdown box option

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.