JavaScript list listbox full selection and inverse selection method _javascript tips

Source: Internet
Author: User

The example of this article describes the implementation of the JavaScript list box listbox selection and the inverse selection method. Share to everyone for your reference. The specific analysis is as follows:

Through the JS code to select and select the list box is often to operate, very practical value.

function Listboxselectdeselect (Listid, isselect) {
  var listbox = document.getElementById (Listid);
  for (var count=0; count < listbox.options.length; count++) {
      listbox.options[count].selected = isselect;
  }
}

Here is a detailed usage example

Click below buttons to select or deselect all options from select box <br> <select id= "Lsbox" name= "Lsbox" siz E= "multiple=" "> <option value=" 1 ">India</option> <option value=" 2 ">united States</opti On> <option value= "3" >China</option> <option value= "4" >Italy</option> <option VA Lue= "5" >Germany</option> <option value= "6" >Canada</option> <option value= "7" >France< /option> <option value= "8" >united kingdom</option> </select> <br> <button onclick= "lis Tboxselectdeselect (' Lsbox ', true); >select all</button> <button onclick= "listboxselectdeselect (' Lsbox ', false);" >deselect all</button> <script> function Listboxselectdeselect (Listid, Isselect) {var listbox = document
  . getElementById (Listid);
  for (var count=0; count < listbox.options.length; count++) {listbox.options[count].selected = Isselect;
}} </script> 

The

wants this article to help you with your JavaScript programming.

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.