简体   繁体   中英

Get value from input date and show in the another input date by ajax

When <input class="boton" type="checkbox"> is changed, get value from <input type='date' id='fechai' name='fechai' class='fechai'> and show it on <input type="date" id="fechai-cambio" name="fechai5"> with ajax. Can include jquery. Ive tried multiple things but I can only get it to show on the alert.... I posted both of them below just in case because the second one is shown within a while. I need for the first date to show in all the boxes that have been checked.

    $('.boton').change(function () {
        var fechai = new Date($('#fechai').val());

         $.ajax({
            type: 'post',
            data: {fechai:fechai},
            success: function(response){
                //Show the var fechai in the #fechai-cambio
             alert(fechai); 
            }
          });


        });
<label for='superv' >Nombre de Equipo</label>
            <select name='superv' id='superv'>
            '<option></option>'";
                while($row = mysqli_fetch_array($superv))
                {
                    echo "<option value='$row[IDSUPERVISOR]'>$row[NOMEQUIPO]</option>";
                }           
        echo"    </select>                     
        <label for='cantp' >Cantidad de Personas</label>
            <input type='text' id='cantp' name='cantp' readonly>
        <label for='razon' >Fecha Inicio</label>
            <input type='date' id='fechai' name='fechai' class='fechai' >
        <br>";

        while($row = mysqli_fetch_array($result)){
         echo ' <tr>
                <td>'.$row['NOMBRE'].' '.$row['APELLIDO_P'].'</td>
                <td class="text-center"><input class="boton" type="checkbox" name="checkbox[]" value="'.$row['IDLIBRETA_PERSONAL'].'"></td>
                <td><input type="date" id="fechai-cambio" name="fechai5" ></td>
                <td>'.$row['NOMBRE'].'</td>

                </tr>';
        }    
        echo "<button id='btn_form' type='button' onclick='realizaGrupo()'>Grabar</button>";

I do not why you want to use AJAX. Where you can simply do like this with jquery

$('.boton').change(function () {
    var fechai = $('#fechai').val();
    $('#fechai-cambio').val(fechai);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM