Z
Z
zvarich19862018-03-05 23:42:03
JavaScript
zvarich1986, 2018-03-05 23:42:03

Why don't you explain it?

What's wrong with the
HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>

    <input type="radio" name="r1" value="5">0
    <input type="radio" name="r1" value="53">1
    <input type="radio" name="r1" value="535">2

    <button onclick="fun1()">Проверить какой из элементов выбран</button>

    <script src="script.js"></script>

</body>


</html>

JavaScript:
function fun1() {
    var radi = document.getElementsByName('r1');
    for (var i = 0; i < radi.length; i++); {
        if (radi[i].checked) {
            alert('Выбран' + i + 'элемент');
        }
    }
}

Gives errors and does not work
What to do tell me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-03-05
@Sanasol

document.querySelector("input[name=r1]:checked")
Of course, I will not correct errors and show them too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question