How to obtain the value of the select drop-down box (option does not have a value attribute) _ javascript tips-js tutorial

Source: Internet
Author: User
The values in the select drop-down box are divided into two situations: option without value attribute and value Attribute. The specific implementation code is given below, for more information about how to obtain the select drop-down box value, see:
1. When the option in the drop-down box does not have the value Attribute

The Code is as follows:


Student ID Name AgeScript window. onload = funciton () {var param = document. getElementById ("param1"); param. onchange = getParam () {var text = param. value;} script 2. when the option in the drop-down box has the value attribute, the Code is as follows:
Student ID
Name
Age

Script
Window. onload = funciton (){
Var param = document. getElementById ("param1 ");
Param. onchange = getParam (){
Var selectIndex = param. selectIndex; // obtain the cited number of the selected option
Var text = param. options [selectIndex]. text;
Script

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.