Dropdownlist controls ListBox content

Source: Internet
Author: User

I. I am working on a project to prevent page refreshing and use dropdownlist to control the content of ListBox.

The Code is as follows:

  1. Function deletemethod ()
  2. {
  3. VaR objselect = Document. getelementbyid ('listbox1 ');
  4. If (objselect. selectedindex! =-1)
  5. {
  6. Objselect. Remove (objselect. selectedindex );
  7. }
  8. If (document. getelementbyid ('listbox1'). Options. Length <3)
  9. {
  10. Document. getelementbyid ('slt _ person'). Disabled = false;
  11. }
  12. }
  13. Function checkstate ()
  14. {
  15. If (document. getelementbyid ('listbox1'). Options. Length = 0)
  16. {
  17. Document. All. Remove. Disabled = true;
  18. }
  19. Else
  20. {
  21. Document. All. Remove. Disabled = false;
  22. }
  23. If (document. getelementbyid ('listbox1'). Options. Length = 3)
  24. {
  25. Document. getelementbyid ('slt _ person'). Disabled = true;
  26. }
  27. }
  28. Function additem ()
  29. {
  30. VaR text = Document. All. slt_person.options [document. All. slt_person.selectedindex]. text;
  31. VaR values = Document. All. slt_person.options [document. All. slt_person.selectedindex]. value;
  32. VaR list = Document. getelementbyid ('listbox1 ');
  33. If (values! = '-1 '&&! Isexist (values, list ))
  34. {
  35. List. Options. Add (New Option (text, values, values, 0 ));
  36. }
  37. }
  38. Function isexist (SS, LL)
  39. {
  40. VaR length = Document. getelementbyid ('listbox1'). Options. length;
  41. For (VAR I = 0; I <length; I ++)
  42. {
  43. If (LL. Options [I]. value = SS)
  44. Return true
  45. }
  46. Return false;
  47. }

2. listbox1 binds the database content, and then binds the script to the event on the corresponding control.

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.