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

237
Views
Onkeyup event for multiple input field in JavaScript or Jquery?

I have multiple input fields and I want to apply key up JavaScript event on some of input field. Basically, I want to do some expense calculation and I want to get total expenses and set final expense amount in input field to display. So, I tried to apply keyup on multiple input field but did not work.

$('#tripfuel','#cardfee','#loadrepair','#shoprepair','#truckrent','#comcheck','#advance','#othercharge').on('keyup', function () {
        var fuel = document.getElementById('tripfuel').value;
        var cardfee = document.getElementById('cardfee').value;
        var onloadrepair = document.getElementById('loadrepair').value;
        var shoprepair = document.getElementById('shoprepair').value;
        var trailerrent = document.getElementById('truckrent').value;
        var comcheck = document.getElementById('comcheck').value;
        var advance = document.getElementById('advance').value;
        var miscellenous = document.getElementById('othercharge').value;
        var expense = parseFloat(amount)-parseFloat(fuel)-parseFloat(cardfee)-parseFloat(onloadrepair)-parseFloat(shoprepair)-parseFloat(trailerrent)-parseFloat(comcheck)-parseFloat(advance)-parseFloat(miscellenous);
        console.log("Total Expense : || "+expense); 
        document.getElementById('totalamount').value = parseFloat(expense).toFixed(2);
    }); 

Screenshot to display fields

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

0

apply the class of all of your expenses input like

 <input type="text" class="expenses" />

then get the total value like this.

$('.expenses').on('keyup', function () {
   let totalExpense = 0;
    $(document).find("input.expenses").each(function(){
       totalExpense += parseFloat($(this).val())
   })
});
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!