How to select a radio input within a div

0

I have a JS code that when I select one of the 2 radio inputs of a form, it returns me if the question is correct or incorrect. I need to please know how to select the radio click where you click on the div because when I click on the div it only changes the color but it does not leave the selected radio.

The code is as follows

JS:

$("#listado li ul li div").click(function(){
        if($(this).attr('class')=='correcto seleccionado'){            /*si acierta*/
            $(this).removeClass().addClass('acertado_usuario');
            $(this).siblings('.normal').removeClass().addClass('resto');
        }
        else if($(this).attr('class') == 'normal seleccionado') {       /*si no acierta*/
            $(this).removeClass().addClass('fallado');
            $(this).siblings('.normal').removeClass().addClass('resto');
            $(this).siblings('.correcto').removeClass().addClass('acertado');
        }
        $(this).attr("disabled", true);
        $(this).siblings().attr("disabled", true);
        $(this).css('cursor', 'default');                         
        $(this).siblings().css('cursor', 'default');              

        correctas = $('.acertado_usuario').size();
        falladas = $('.fallado').size();
        no_answer = $('.correcto').size();
        nota = ((correctas - (falladas /(4-1)))/total) * 10;
        nota4 = ((correctas / total) - (falladas /(4 * total))) * 10;

        $("#resultado_a").html("Correctas: "+correctas);
        $("#resultado_b").html("Incorrectas: "+falladas);
        $("#resultado_c").html("Sin respuesta: "+no_answer);
        $("#resultado_d").html("Nota: "+nota.toFixed(2));
    });

And the form contains the following radios:

<div class="correcto"><input type="radio" value="1" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo $result['answer1'];?></div>
<div class="normal"><input type="radio" value="2" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo $result['answer2'];?></div>
    
asked by Vieira 21.02.2018 в 16:27
source

2 answers

0

$('#correcto').click(function(){
  $('#chkCorrecto').click();
});

$('#normal').click(function(){
  $('#chkNormal').click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

<form action="#">
<div id="correcto">Correcto</div>
<div id="normal">Normal</div>
<input type="radio" name="chkComprobacion" id="chkCorrecto" value="correcto" style="visibility: hidden;">
<input type="radio" name="chkComprobacion" id="chkNormal" value="normal" style="visibility: hidden;">
<button type="submit">Enviar</button>
</form>

try this to see if the form is sent with the corresponding check

    
answered by 21.02.2018 в 17:10
0

If I put this code outside of the JS that I put on top, yes it selects the radio, but the radio button keeps appearing.

$('.correcto').click(function() {
    $(this).find('input').prop('checked', true)    
    });
$('.normal').click(function() {
    $(this).find('input').prop('checked', true)    
});

I think what I'm looking for is to do something like this:

$(".normal :radio").hide().click(function(e)
    
answered by 21.02.2018 в 17:34