Не работает JS

Здравствуйте!

Попробовал запустить данный скрипт на пустом чанке, но по какой то причине он не работает. Сам скрипт переключает инпуты методом js. У кого какие идеи почему может не работать?
<div id="tabs">
                        <input name="i-1" type="radio">
                        <input name="i-2" type="radio">
                        <input name="i-3" type="radio">
                    </div>
<script>
                        window.onload = function () {
                            var container, input-box, i, j;
                        
                            container = document.getElementById( 'input-box' );
                        
                            input-box = container.getElementsByTagName( 'input' );
                        
                            for ( i = 0; i < input-box.length; i++ ) {
                                input-box[i].addEventListener( 'click', function () {
                                    for ( j = 0; j < input-box.length; j++ ) {
                                        if ( input-box[j] !== this ) {
                                            input-box[j].checked = false;
                                        }
                                    }
                                }, true );
                            }
                        };
                    </script>
Буду очень благодарен за помощь.
Oleg
12 мая 2019, 13:02
modx.pro
583
0

Комментарии: 2

Василий Stepanov
12 мая 2019, 13:16
+1
1.input-box исправь на inputbox.
2. И
container = document.getElementById( 'input-box' );
исправь на
container = document.getElementById( tabs' );
Весь код
<div id="tabs">
    <input name="i-1" type="radio" checked>
    <input name="i-2" type="radio">
    <input name="i-3" type="radio">
</div>
<script>
    window.onload = function () {
        var container, inputbox, i, j;
        
        container = document.getElementById( 'tabs' );    
        inputbox = container.getElementsByTagName( 'input' );
        
        for ( i = 0; i < inputbox.length; i++ ) {
            inputbox[i].addEventListener( 'click', function () {
                for ( j = 0; j < inputbox.length; j++ ) {
                    if ( inputbox[j] !== this ) {
                        inputbox[j].checked = false;
                    }
                }
            }, true );
        }
    };
</script>
    Oleg
    12 мая 2019, 21:37
    0
    Благодарю, запамятовал как то.
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    2