Js gets the selected value of the select tag, js gets the select tag

Source: Internet
Author: User

Js gets the selected value of the select tag, js gets the select tag

Var obj = document. getElementByIdx_x ("testSelect"); // locate the id

Var index = obj. selectedIndex; // select an index

Var text = obj. options [index]. text; // select the text

Var value = obj. options [index]. value; // The selected value.


Obtain the selected select value in jQuery.

Method 1
$ ('# TestSelect option: selected'). text (); // The selected text

$ ('# TestSelect option: selected'). val (); // The selected value.

$ ("# TestSelect"). get (0). selectedIndex; // Index

 

Method 2
$ ("# TesetSelect"). find ("option: selected"). text (); // The selected text
....... Val ();
....... Get (0). selectedIndex;


How does js obtain the select option value?

Document. getElementById ("sect"). value ----- This is to obtain the selected value
Document. getElementById ("sect"). options ------ this is to obtain all the values in the select statement, which is an array

How does JS obtain the option with a value equal to 4 under the SELECT tag and make the option selected ?? Only javascript is supported.

Var str1;
Var myCheckbox1 = document. getElementsByName ("taskCrcletime ");
For (var I = 0; I <myCheckbox1.length; I ++ ){
If (myCheckbox1 [I]. value = 4 ){
Str1 + = myCheckbox1 [I]. value;
Document. getElementsByName ("taskCrcletime"). checked = true;
}
}

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.