Select radio input in div

-1

I would need to know please how I select an input that is inside a div. At the same time I would like to hide the circle of the radio ... I tried this:

$(".calendar div").click(function(e){
     $(this).closest(".calendar").find("div").removeClass("selected");
     $(this).addClass("selected").find(":radio").click();
});

and I have this code:

<form>
<div class="correcto"><input type="radio" value="3" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo $result['answer3'];?></div>

<div class="normal"><input type="radio" value="3" id='radio1_<?php echo $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo $result['answer3'];?></div>
</form>

$(document).ready(function(){ 
    total = $('.correcto').size();
    $("#listado li ul li div").mouseenter(function(){
        if($(this).attr('class')=='normal' || $(this).attr('class')=='correcto'){
            $(this).addClass('seleccionado');
        }
    });
    $("#listado li ul li div").mouseleave(function(){
        if($(this).attr('class')=='normal seleccionado'){
            $(this).removeClass().addClass('normal');
        }
        if($(this).attr('class')=='correcto seleccionado'){
            $(this).removeClass().addClass('correcto');
        }
    });
    $("#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));
    });
});

Thank you very much in advance

    
asked by Vieira 21.02.2018 в 13:02
source

1 answer

0

You are using the selector incorrectly in your JQuery function

Taking only the following code you can access the input in several ways.

<form>
 <div class="correcto"><input type="radio" value="3" id='radio1_<?php echo 
 $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo 
 $result['answer3'];?></div>

 <div class="normal"><input type="radio" value="3" id='radio1_<?php echo 
 $result['id'];?>' name='<?php echo $result['id'];?>'/> <?php echo 
 $result['answer3'];?></div>
</form>

Using:

$('.correcto input')

With this you select the first input.

If you want to select the second would be something similar:

$('.normal input')

If you want to select the two input: jquery: radio Selector

$(':radio') esto es equivalente a $('[type=radio]')

Being more specific when selecting all the input:

$('form div :radio')

Regarding the fact that you want to hide the radio circle, it is not clear to me what you are trying to do.

    
answered by 21.02.2018 в 16:46