Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Jquery onkeyup not working on boostrap modal. I'm using laravel blade template

I want to auto compute the extract fee, estimated value and num vehicle after I input a value in to tonnage.

I used a Bootstrap modal for this but as soon I put a value in tonnage it doesn't work. I'm confused right now.

$(document).ready(function() {
  $('body').on('keyup', '#tonnage', function() {
    var tonnage = $("#tonnage").val();
    var num_vehicle;
    if (tonnage <= 20) {
      num_vehicle = 1;
      $("#num_vehicle").val(num_vehicle);
    } else {
      num_vehicle = tonnage / 20;
      $("#num_vehicle").val(num_vehicle);
    }

    var total_estimate_value = num_vehicle * 6000;
    $("#estimated_value").val(total_estimate_value);
    var total_extraction_fee = num_vehicle * 6000 * 0.1;
    $("#extraction_fee").val(total_extraction_fee);
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="col-md-6"> 
  <label for="inputCity" class="form-label">Volume/Tonnage</label> 
  <input type="text" class="form-control" id="tonnage" name="tonnage"> 
</div>
<div class="col-md-6">
  <label for="inputCity" class="form-label">Extraction Fee</label>
   <input type="text" class="form-control" id="extraction_fee" name="extraction_fee" readonly="">
</div>
<div class="col-md-6">
   <label for="inputCity" class="form-label">Estimated Value</label>
   <input type="text" class="form-control" id="estimated_value" name="estimated_value" readonly="">
</div>
<div class="col-md-6">
   <label for="inputCity" class="form-label">No. of Vehicle</label>
   <input type="text" class="form-control" id="num_vehicle" name="num_vehicle" readonly="">
 </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The main issue is because you don't round the result of tonnage / 20, so you get a fraction of a vehicle, eg. 21 tons = 1.05 vehicles, instead of found up to the nearest integer, eg. 21 tons = 2 vehicles. This can be achieved using Match.ceil().

Also, be careful of implicit type conversions from string to int/floats. It's better to be explicit with this, as in the following example:

jQuery($ => {
  $(document).on('keyup', '#tonnage', function() {  
    var tonnage = parseFloat($(this).val());
    var numberOfVehicles = Math.ceil(tonnage / 20);
    $('#num_vehicle').val(numberOfVehicles);
    
    var total_estimate_value = numberOfVehicles * 6000;
    $("#estimated_value").val(total_estimate_value);
    
    var total_extraction_fee = numberOfVehicles * 6000 * 0.1;
    $("#extraction_fee").val(total_extraction_fee);
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="col-md-6">
  <label for="inputCity" class="form-label">Volume/Tonnage</label>
  <input type="text" class="form-control" id="tonnage" name="tonnage">
</div>
<div class="col-md-6">
  <label for="inputCity" class="form-label">Extraction Fee</label>
  <input type="text" class="form-control" id="extraction_fee" name="extraction_fee" readonly="">
</div>
<div class="col-md-6">
  <label for="inputCity" class="form-label">Estimated Value</label>
  <input type="text" class="form-control" id="estimated_value" name="estimated_value" readonly="">
</div>
<div class="col-md-6">
  <label for="inputCity" class="form-label">No. of Vehicle</label>
  <input type="text" class="form-control" id="num_vehicle" name="num_vehicle" readonly="">
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!