JS get Radio Check value instance code

Source: Internet
Author: User
Tags radarr

Use JS to get radio selected value, which is often used in the submission page, and also describes the method of not selecting and can get radio value.


    1. Text
    2. Do not choose to get the value of radio

    3. Dollar
    4. Yen
    5. Euro

Copy Code

Native JS mode: (Native DOM operations will also treat text as a node, so there will be nextsibling)

    1. var USD = Document.getelementsbyname ("Money") [0].nextsibling.nodevalue;
    2. var yen = Document.getelementsbyname ("Money") [1].nextsibling.nodevalue;
    3. var euro = document.getelementsbyname ("Money") [2].nextsibling.nodevalue;
Copy Code

The jquery method gets the radio value.

    1. $ (' input[name= ' money "]:checked '). Next (' span '). HTML ();

    2. USD

    3. JPY
    4. Euro

    5. Dollar

Copy Code

The following is to be selected, only to determine if there is no choice.

    1. function Radiovalue () {

    2. var Radarr = document.getelementsbyname ("Radiov");
    3. var radvalue = "";
    4. alert (radarr.length);
    5. for (var i=0; i
    6. Alert (radarr[i].checked+ "" +radarr[i].name + "+ radarr[i].value);
    7. if (radarr[i].checked) {
    8. Radvalue = Radarr[i].value;
    9. }
    10. }

    11. if (radvalue! = NULL && Radvalue! = "") {

    12. alert (Radvalue);
    13. }else{
    14. Alert ("Please select");
    15. }

    16. }

Copy Code
  • 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.