mardi 27 mars 2018

Repeat cycle with IF

I have text on the button that changes when a radio button is clicked. But when I click the button twice the text does not appear anymore. And I want some cycle/repeat for when clicking the radiobuttons more than once the text on the button appears. Some help?

HTML

<nav class="navbar2 navbar-expand-sm navbar-dark fixed-bottom">
        <div id="navbarbackground" class="container-fluid">
            <div class="navbar" id="nav-content">
                <label class="labl icon-package-flat">
                    <input type="radio" onclick="window.location='#formulario';" id="radioInfo" name="radioname" value="Submeter pedido de Informação geral" checked="checked" />
                    <div class="text"><center class="iconcenter"><i class="icon icon-info"></i></center>Informação geral</div>
                </label>
                <label class="labl icon-package-flat">
                    <a href="#formulario"></a>
                    <input type="radio" onclick="window.location='#formulario';" id="radioTestDrive" name="radioname" value="Submeter pedido de Test drive" />
                    <div class="text"><center class="iconcenter2"><i class="icon icon-test_drive"></i></center>Test drive</div>
                </label>
                <label class="labl icon-package-flat">
                    <input type="radio" onclick="window.location='#formulario';" id="radioFinancing" name="radioname" value="Submeter pedido de Financiamento" />
                    <div class="text"><center class="iconcenter2"><i class="icon icon-calculator"></i></center>Financiamento</div>
                </label>
                <label class="labl icon-package-flat">
                    <input type="radio" onclick="window.location='#formulario';" id="radioCatalog" name="radioname" value="Submeter pedido de Catálogo" />
                    <div class="text"><center class="iconcenter2"><i class="icon icon-printed"></i></center>Catálogo</div>
                </label>
            </div>
        </div>
    </nav>

Javascript

 $("[name='radioname']").click(function () {
            $(this).parent().find('.radio').removeClass('selected');
            $(this).addClass('selected');

            var val = $(this).attr('data-value');

            if ($(this).id == "radioInfo") {
                $("#lblOpcao").text("Submeter pedido de Informação geral");
            }

            if ($(this).id == "radioFinancing") {
                $("#lblOpcao").text("Submeter pedido de financiamento");
            }

            if ($(this).id == "radioTestDrive") {
                $("#lblOpcao").text("Submeter pedido de Test drive");
            }

            if ($(this).id == "radioCatalog") {
                $("#lblOpcao").text("Submeter pedido de Catálogo");
            }

            $("#lblOpcao").text($(this).val());
            //alert(val);
            $(this).parent().find('input').val(val);        
        });

        function toggle(button) { if (radio.value == "OFF") { radio.value = "ON"; } else { radio.value = "OFF"; } }

Thank you!

Aucun commentaire:

Enregistrer un commentaire