Select Checkbox value

Asked

Viewed 44 times

0

How can I select the value of the checkbox below? I need when I click the checkbox to get the value of the checkbox clicked.

https://jsfiddle.net/ckzq8yef/

1 answer

0

You can get the element by using the function click jQuery:

$("[type='checkbox']").click(function() {
  // verifica se está selecionado
  if($(this).is(':checked')){
      console.log($(this).val())
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
  <div class="col-md-3">
    <div class="checkbox">
      <label class="">
                      <div>
                        <input type="checkbox" id="checktipo" value="fisica"  name="checktipo[]" />
                      </div> Pessoa Física
                    </label>
    </div>
  </div>
  <div class="col-md-3">
    <div class="checkbox">
      <label class="">
                      <div>
                        <input type="checkbox" id="checktipo" value="juridica" name="checktipo[]" />
                      </div> Pessoa Jurídica
                    </label>
    </div>
  </div>
  <div class="col-md-3">
    <div class="checkbox">
      <label class="">
                      <div>
                        <input type="checkbox" id="checktipo" value="contato" name="checktipo[]" />
                      </div> Contato
                    </label>
    </div>
  </div>

Browser other questions tagged

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