JS gets the value of the Select Drop-down box

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax drop get html http index javascript public

This is a simple and practical web effects get Select value Oh, we use getElementById to get select ID=CC, and then we use option to index the value of the current option Oh

<!doctype HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ""
<html xmlns= "http://www.w3.org/1999/xhtml"
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>js Gets the value of the Select Drop-down box </title>
<script language=" Web Effects "
  function GetValue ()
 {
  var t = document.getElementById ("cc");
  alert (t.options[t.selectedindex].value);
 }
 
 function addselect ()
 {
    var selectvar = docuemnt.all (' Select1 ');
    var options = selectvar.options;
    var index = Selectvar.selectedindex;
    var selectvalue = Options[index];
    options[i] = new option ("added value", "values");
 }
</script>
</head>

<body>
<select name= "Select1" id= "CC" onchange= "GetValue ();"
    <option value= "111c" >--contributors--</option>
    <option Value= "jzread.com" >--administrator--</option>
 </select>
 <a href= "# onclick=" Addselect ();" > Add options to select </a>
</body>
</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.