PHP Update dynamically checkboxes

0

I'm having trouble performing a function on a scheduling system,

Follow the photo:

Ineedtodothefollowing,whentheuserselectsadatethesystemmakesaqueryinthedatabaseandfillsinthecheckboxes.ThequeryinthedatabaseIcando,myproblemisincreatinganeventchangueinthedatefieldbycallingthequeryandpopulatingthecheckboxes.

//

InthepreviousversionofthesystemIdidusingAjax,howeverIhadaselectdatefieldandaselecttimefield,soIusedthescriptbelow,buttheclientrequestedtoswitchtothistabletemplate.

<scripttype="text/javascript">
      $(document).ready(function(){
         $("select[name=predata]").change(function(){
$("select[name=prehora]").html('<option value="">Carregando...</option>');
            $.post("ajax-prehora.php?predata=13/06/2016",
                  {predata:$(this).val()},
 function(valor){
                     $("select[name=prehora]").html(valor);
                  }
                  )
         })          
             })

    
asked by anonymous 21.06.2016 / 16:48

1 answer

0

The following is a simple example to show how checkboxes can be dynamically changed according to the value of a text field. Schedules are chosen by a calculation that can be overwritten by a query with Ajax. See this page of the jQuery documentation if you need further explanation of how checkboxes are dynamically selected.

I put here in JSFiddle the same example using an Ajax "simulation."

<!DOCTYPE html>
<script
  src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script><scripttype="text/javascript">
$(document).ready(function() {
    $("input[name='predata']").keyup(function() {
        var data = $(this).val();
        var horarios = [];
        if (parseInt(data) % 2 == 0 ) horarios.push("08");
        if (parseInt(data) % 3 == 0 ) horarios.push("09");
        if (parseInt(data) % 5 == 0 ) horarios.push("10");
        $( "input[type='checkbox']").val(horarios);
    });
})
</script>

<html>
<body>
<input type="text" name="predata">
<p>
<input type="checkbox" class="prehora" id="hora08" value="08">
<label for="hora08">08:00</label>
<input type="checkbox" class="prehora" id="hora09" value="09">
<label for="hora09">09:00</label>
<input type="checkbox" class="prehora" id="hora10" value="10">
<label for="hora10">10:00</label>
</p>
</body>
</html>
    
21.06.2016 / 20:57