0

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

Why can`t to get radio button value ?

1 Answer 1

1

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().

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. it works with radio[i].value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.