Select one or more Checkboxs release send button

Asked

Viewed 51 times

-1

Hello Folks I am in need of a help on the following question:

When I select a checkbox the send button will not be available, but if you select one or more is available. follow the code:

<div class="selecionar-todos">
	<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="od" > SELECIONAR TODOS
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="um"> UM
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="dois"> DOIS
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="tres"> TRÊS
</div>

<button type="button" class="btn btn-success">ENVIAR</button>


/* SCRIPT SELECIONAR TODOS (FUNCIONANDO) */

<script>
 $("#od").change(function(){
            if(this.checked){
              $(":checkbox[name=tecnologia]")
              .attr("checked","checked");
            } else {
                $(":checkbox[name=tecnologia]")
                .removeAttr("checked");
            }
        });

</script>


 SCRIPT LIBERAR BOTAO QUE FUNCIONA COM INPUT TYPO TEXT (FUNCIONANDO) que tentei implementar no tipo CHECKBOX


<script>
	
	validate();
        $(':checkbox[name=tecnologia]').change(validate);
 
    function validate() {
        if (
            $(':checkbox[name=tecnologia]').val().length > 1) {
            $("button[type=submit]").prop("disabled", false);
        }
        else {
            $("button[type=submit]").prop("disabled", true);
        }
    }

</script>

1 answer

0


Voce can try to put an id in the input field and debug the button as follows:

<div class="selecionar-todos">
    <input class="form-check-input" name="tecnologia" type="checkbox" value="" id="od" > SELECIONAR TODOS
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="um"> UM
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="dois"> DOIS
</div>

<div class="grupos-imputs">
<input class="form-check-input" name="tecnologia" type="checkbox" value="" id="tres"> TRÊS
</div>

<button id="enviar" type="button" class="btn btn-success">ENVIAR</button>


/* SCRIPT SELECIONAR TODOS (FUNCIONANDO) */

<script>
 $("#od").change(function(){
            if(this.checked){
              $(":checkbox[name=tecnologia]")
              .attr("checked","checked");
            } else {
                $(":checkbox[name=tecnologia]")
                .removeAttr("checked");
            }
        });

</script>


 SCRIPT LIBERAR BOTAO QUE FUNCIONA COM INPUT TYPO TEXT (FUNCIONANDO) que tentei implementar no tipo CHECKBOX


<script>
    $('#um, #dois, #tres').change(function() {
        if ($('input:checkbox:checked').length > 1){

            document.getElementById("enviar").disabled = true;
        }
        else {
            document.getElementById("enviar").disabled = false;
        }        
    });

</script>

can also using jQuery

$("#enviar").attr("disabled", true); //para desativar o botao
$("#enviar").attr("disabled", false); //para ativar o botao
  • Hello friend, thank you for the answer, but I did the test here and it didn’t work, did you run the adjustment? my impression is that it is not . length not used. now I can’t remember which to use.

  • I modified it, try it with this

  • ball show, it worked out! Thanks.

  • Pleasure to help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.