Questions in accordion

0

Hello, good morning I have a question class in an accordion with the data brought in an ajax and I would like you to say if I answer question 1 by clicking on the button the background of that question will be colored I have an onclick this is the function of that onclick

function autocompletar_tec_ins_inc(){
    //alert("ejecutando autocompletar_tec_ins_inc...");


}







//funcion autocompletar_tec_ins_inc

function Fagregartecins_inc_1(){
    //alert("Incumplió rta1");
if (confirm("DESEA ENVIAR AL TECNICO AL INCUMPLIMIENTO")){



        tec_inc_id_tecnicos_1 = $('#txt_tec_ins_inc_1').val();
        tec_inc_id_pregunta_1 = 1; //$('#txt_tec_inc_id_pre_2').val();
        if(tec_inc_id_tecnicos_1 == '' || tec_inc_id_tecnicos_1 == null){
            alert('Debe seleccionar un técnico.');
            return;
        }

        var datosTecInc1 = {
                tec_inc_id_tecnicos         : tec_inc_id_tecnicos_1,
                tec_inc_id_pregunta         : tec_inc_id_pregunta_1
            };

        //alert("agregando tecnico..."  + tec_inc_id_tecnicos_1);
        $.post('php/agregartecinc.php', datosTecInc1, function(data, textStatus, xhr) {
                //alert("Procesando...");
                if (data == 0){
                    alert('No se pudo procesar Se encuentra repetido');
                    return;
                }
                if (data == 2){
                    alert('No se ha ingresado el técnico a la inspeccion.');
                    return;
                }
                if (data == 3){
                    alert('No se pudo procesar. Error al insertar.');
                    return;
                }
                if (data == 5){
                    alert('Cedula de tecnico no encontrada.');
                    return;
                }

                if (data == 1){

                    alert('Se ha guardado correctamente el registro: ' + data);



                    $.post('php/cuadrilla_actualiza.php', datosTecInc1, function(data2, textStatus, xhr) {
                        //alert(data2);
                        $('#datoscuadrilla').html(data2);
                    });
                    return;
                }
                alert('Error:' + data);

        }); 
    return;
}

}
    
asked by JSACTM Music 08.10.2018 в 15:01
source

1 answer

0

To do what you want, you could create a class in CSS which would have the characteristics you need ( background-color, color, font-size, etc ) and assign it to the selected radius:

$('input:radio').change(function(){
  var $this = $(this);
  $this.closest('.container').find('div').removeClass('selected');
  $this.closest('.color').removeClass('selected');
  $this.closest('.color').addClass('selected');
});
legend {
    background-color: #000;
    color: #fff !important;
    padding: 3px 6px;
}

.output {
    font: 1rem 'Fira Sans', sans-serif;
}

input {
    margin: .4rem;
}

.selected {
    background-color: red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <form>
    <fieldset>
        <legend>¿De qué color era el caballo negro de Napoléon?</legend>

        <div class="color">
            <input type="radio" id="negro" 
                   name="test" value="negro" />
            <label for="huey">Negro</label>
        </div>

        <div class="color">
            <input type="radio" id="blanco" 
                   name="test" value="blanco" />
            <label for="dewey">Blanco</label>
        </div>

        <div class="color">
            <input type="radio" id="gris" 
                   name="test" value="gris" />
            <label for="louie">Gris</label>
        </div>
    </fieldset>
</form>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

In summary, we work with the change event of the element, and before assigning the background-color to the selected radius , we take care of removing it with the functions closest and removeClass

PS: This example uses JQuery

You told us =)

    
answered by 08.10.2018 в 16:21