Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jquery how to get list of checked radio button value?

I have this jquery script

  function radiolist() {
        var radioChecked = [];
        var radios = $("input[type='radio']");
        //alert(radios.length);
        
        for (var i = 0; i < radios.length; i++) {
            if (radios[i].checked) {
                radioChecked.push(radios[i].val());
            }
        }
        alert(radioChecked);
    }

I want to save the list of checked radio buttons in the radioChecked array and access them. But I get the following error

Uncaught TypeError: radios[i].val is not a function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why can`t to get radio button value ?

>Solution :

When you index an element in jQuery, it doesn’t rewrap the element in jQuery. So, you can either use the vanilla javascript approach with radios[i].value, or rewrap it in jQuery with $(radios[i]).val().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading