lundi 5 février 2018

Sum and multiply text-boxes in laravel framework

Currently I'm doing my project using the Laravel framework and I'm just a beginner. I have a problem: when I sum and multiply the text-boxes, my program does not display the result. I wonder if my code is correct. Here is my form code:

<div class="form-group">
        <strong>Rate Lecture Per Hour (RM) :</strong>
        {!! Form::text('lecturePerHour', null, array('placeholder' => 'Rate Lecture Per Hour (RM)','class' => 'form-control', 'id' => 'lecturePerHour', 'onkeyup' => 'calc()')) !!}
    </div>
    <div class="form-group">
        <strong>Rate Tutorial Per Hour (RM) :</strong>
        {!! Form::text('tutorialPerHour', null, array('placeholder' => 'Rate Tutorial Per Hour (RM)','class' => 'form-control', 'id' => 'tutorialPerHour', 'onkeyup' => 'calc()')) !!}
    </div>
    <div class="form-group">
        <strong>Total Working Hour per Month (Lecture) :</strong>
        {!! Form::text('lectureWorkTime', null, array('placeholder' => 'Total Working Hour (Lecture)','class' => 'form-control', 'id' => 'lectureWorkTime', 'onkeyup' => 'calc()')) !!}
    </div>
    <div class="form-group">
        <strong>Total Working Hour per Month (Tutorial) :</strong>
        {!! Form::text('tutorialWorkTime', null, array('placeholder' => 'Total Working Hour (Tutorial)','class' => 'form-control', 'id' => 'tutorialWorkTime', 'onkeyup' => 'calc()')) !!}
    </div>
    <div class="form-group">
        <strong>Total Salary Per Month (RM) :</strong>
        {!! Form::text('totalSalary', null, array('placeholder' => 'Total Salary Per Month (RM)','class' => 'form-control', 'id' => 'totalSalary')) !!}
    </div>

And this is my Javascript code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
    function calc()
    {
      var value1 = parseFloat(document.getElementsByName('lecturePerHour').value);
      var value2 = parseFloat(document.getElementsByName('tutorialPerHour').value);
      var value3 = parseFloat(document.getElementsByName('lectureWorkTime').value);
      var value4 = parseFloat(document.getElementsByName('tutorialWorkTime').value);

      var result = (value1*value3)+(value2*value4);
      document.getElementsByName('totalSalary').value = result;
    }
    </script>

Please help me.Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire