Tips for selecting values from the drop-down list

Source: Internet
Author: User
Code:
  1. <HTML>
  2. <Head> <title> obtain the value and text of the selected item in the drop-down list </title>
  3. <Body>
  4. <SCRIPT>
  5. // Obtain the text of the selected item in the drop-down list
  6. Function getselectedtext (name ){
  7. VaR OBJ = Document. getelementbyid (name );
  8. For (I = 0; I <obj. length; I ++ ){
  9. If (OBJ [I]. Selected = true ){
  10. Return OBJ [I]. innertext; // the key is to obtain the option text through the innertext attribute of the Option object.
  11. }
  12. }
  13. }
  14. // Obtain the value of the selected item in the drop-down list
  15. Function getselectedvalue (name ){
  16. VaR OBJ = Document. getelementbyid (name );
  17. Return obj. value; // This is simple and can be obtained directly using the Value Attribute of the object.
  18. }
  19. </SCRIPT>
  20. <Select id = "myselect">
  21. <Option value = "Fist"> 1 </option>
  22. <Option value = "second"> 2 </option>
  23. <Option value = "third"> 3 </option>
  24. </SELECT>
  25. <Input type = "button" value = "selected text" onclick = "alert (getselectedtext ('myselect');"/>
  26. <Input type = "button" value = "selected value" onclick = "alert (getselectedvalue ('myselect');"/>
  27. </Body>
  28. </Html>
  29. Get the value of the selected item from the drop-down list in IE6
  30. <SCRIPT>
  31. Function U ()
  32. {
  33. VaR _ select = Document. getelementbyid ("SS ")
  34. VaR JJ = _ select. Options [_ select. selectedindex]. value;
  35. Document. Write (jj );
  36. }
  37. Using this method directly may cause problems.
  38. // Obtain the value of the selected item in the drop-down list
  39. Function getselectedvalue (name ){
  40. VaR OBJ = Document. getelementbyid (name );
  41. Return obj. value; // This is simple and can be obtained directly using the Value Attribute of the object.
  42. }
  43. </SCRIPT>

 

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.