JS Gets the sample code for the selected value in select (Multiple-selection dropdown)

Source: Internet
Author: User
Through JS to get Select (Multiple select Drop-down) of the selected value, the specific implementation of the following, there is a need for friends can refer to, I hope to help you Copy CodeThe code is as follows:


<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title> New Document </title>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<body>

<script language= "JavaScript" >
<!--
function Checkselect (objname) {
o = document.getElementById (objname);
t = document.getElementById ("Output");
var count=0;
var intvalue= "";
for (i=0;i<o.length;i++) {
if (o.options[i].selected) {
Intvalue+=o.options[i].value+ ",";
count++;
}
}
T.value=intvalue.substr (0,intvalue.length-1);
alert (count);

}
-->
</script>
<select name= "Objsel" Size=8 multiple>
<option value= "0" selected> Please select
<option value= "1" > Test One
<option value= "2" > Test II
<option value= "3" > Test three
<option value= "4" > Test four
<option value= "5" > Test Five
</select>
<input type= "button" onclick= "Checkselect (' Objsel ');" value= "Output" >
Selected items: <input type= "text" name= "Output" >
</body>

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.