MoteCL
MoteCL

Reputation: 228

How to calculate the rest of the inputs

I have a table and I am calculating the difference of hours but only first row of the table calculates me. and I have a method where created a new table is if the date is different

    $(document).ready(function() {
      getHrs();
    });
    function getHrs()
    {
            hstart=$('#horaInicio').val();
            hend=$('#horaTermino').val();

            hr1 = (hstart).split(":");
            hr2 = (hend).split(":");
            hrstart=(hr1[0]);
            minstart=(hr1[1]);
            hrend=(hr2[0]);
            minend=(hr2[1]);
            totalstart=parseInt((hrstart*60)) + parseInt(minstart);
            totalend=parseInt(hrend*60) + parseInt(minend);
            rsthr=(totalstart - totalend);
            total=(rsthr / 60).toFixed(2);


            $('#resultado').val(total);
          }

here my table, I create a table for each different day.

<?php if ($seguimientos): ?>
<?php $fechas = array();
      foreach ($seguimientos as $seguimiento) {
         $fechas[$seguimiento-> fecha][] = $seguimiento;

      }
?>
<?php foreach ($fechas as $fecha): ?>
<table class="table table-hover">
<thead>
    <tr>
        <th>Fecha</th>
        <th>Orden</th>

    </tr>
</thead>
<?php   foreach ($fecha as $seguimiento): ?>
<tr>
    <td>
        <?php echo $seguimiento-> fecha; ?>
    </td>
    <td>
        <?php echo $seguimiento-> horaInicio; ?>
  <input type="hidden" id="horaInicio" value=" echo $seguimiento-> horaInicio;">
    </td>
    <td>
        <?php echo $seguimiento-> horaFin; ?>
<input type="hidden" id="horaInicio" value=" echo $seguimiento-> horaFin;">
    </td>
    <td>
        <input type="text" id="resultado" value="" readonly>
    </td>

</tr>

<?php endforeach; ?>
    </table>
<?php endforeach; ?>
<?php endif; ?>

could be the problem the ID must be unique

Upvotes: 0

Views: 61

Answers (1)

i.terrible
i.terrible

Reputation: 157

Yes, that is the problem, try not to use id's but rather data attributes, or classes. like this: <input type="hidden" data-start="horaInicio" value=" echo $seguimiento-> horaInicio;"> Then your selector becomes: hstart=$('[data-start]').val(); And the same for the other input.

Upvotes: 1

Related Questions