A simple example of JS getting select value and text value, selectvalue

Source: Internet
Author: User

A simple example of JS getting select value and text value, selectvalue

This article mainly introduces a simple example of JS getting select value and text value. If you need a friend, you can refer to it and hope to help you.

The Code is as follows: <select id = "cityList"> <select id = "selectId"> <option value = "0"> 0th </option> </select> <script> var selectObj = document. getElementById ('selectid'); // Add option selectId through the object. add (new Option ("first", "1") selectId. add (new Option ("second", "2") // add option selectId by id. add (new Option ("third", "3") selectId. add (new Option ("fourth", "4") // selectId by using the id (or by adding an object. onchange = function () {// obtain value and text alert (selectObj. value); alert (selectObj. options [selectObj. selectedIndex]. text); // obtain the value and text alert (selectId. value); alert (selectId. options [selectId. selectedIndex]. text); // You can also obtain the value and text alert (this. value); alert (this. options [this. selectedIndex]. text) ;}; </script> from http://www.3lian.com/edu/2014/02-27/131363.html

Related Article

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.