How to create dynamic checkboxes?

0

I'm using the following commands to create the checkboxes

 if (isset($finded_documents)) {
                      // inicia a variável que vai guardar os checkboxes
                      $checkboxes = '';

                      // para cada documento encontrado
                      foreach ($finded_documents as $check) {
                        // acrescenta um Checkbox
                        $checkboxes .= '<div class="custom-control custom-checkbox">'
                          . "<input id='check-$check[id]' type='checkbox' value='$check[id]' name='docs[]' class='custom-control-input'> "
                          . "<label class='custom-control-label' for='check-$check[id]'>$check[Nome_Documento]</label>"
                          . '</div>';

                      }
                      // mostra os $checkboxes na tela
                      echo $checkboxes;
                    }

                  ?>

I would like that when I click on a checkbox, I would add this command line:

<input type="date" name="data" placeholder="Digite a data do Vencimento"
                           class="form-control"><br>
    
asked by anonymous 13.08.2018 / 15:42

1 answer

0

You can do it this way using pure JS:

HTML:

  <input type="checkbox" id="id_checkbox">
  <p>Digite a data:</p>
  <input id="id_data" name="data" placeholder="Digite a data do Vencimento" type="hidden">


JS:

document.getElementById('id_checkbox').addEventListener('change', function() {
  if(this.checked) {
    document.getElementById('id_data').removeAttribute('type', 'hidden');
    document.getElementById('id_data').setAttribute('type', 'date')
  } else
    document.getElementById('id_data').setAttribute('type', 'hidden'); 
});

I hope you get what you need.

    
13.08.2018 / 17:06