Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8097283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:42:28+00:00 2026-06-05T21:42:28+00:00

I would like the field sub_total to update as various fields are changed instead

  • 0

I would like the field “sub_total” to update as various fields are changed instead of it updating when one particular field is updated(namely: “add_on”)

I have tried adding $(document).ready(function(){ to the top of the code, but it is not calculating at all if i add that.

HTML:

<td>Total Cost Full Day</td>
<input type="text" name="total_full" id="total_full"  />

<td>&nbsp;</td>
    <td>&nbsp;</td>

 <td>Total Cost Half Day</td>
<input type="text" name="total_half" id="total_half"  />

<td>&nbsp;</td>
    <td>&nbsp;</td>


<td>Addon Charge</td>
<input type="text" name="add_on" id="add_on"  />

<td>&nbsp;</td>
    <td>&nbsp;</td>


<td>Sub Total</td>
<input name="sub_total" type="text" id="sub_total" />​

JAVASCRIPT

//Calculate Sub Total


function calculateSubTotal() {

    var SubTotal = +total_full.value + +total_half.value + +add_on.value;

    document.getElementById("sub_total").value = isNaN(SubTotal) ? 0 : SubTotal;
}


document.getElementById("add_on").onchange = calculateSubTotal;
document.getElementById("add_on").onkeyup = calculateSubTotal;​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:42:30+00:00Added an answer on June 5, 2026 at 9:42 pm

    You need to be using jQuery to use something like $(document).ready. Otherwise it won’t work.

    That’s my favorite method, but using something like window.onload works as well. See below… I also changed the calculation of your SubTotal. Unless you declared variables called total_full, total_half, and add_on, you still need to get the elements the same way you got them when assigning your events.

    window.onload=function(){
    //Calculate Sub Total
    
    
    function calculateSubTotal() {
    
        var SubTotal = +document.getElementById("total_full").value + +document.getElementById("total_half").value + +document.getElementById("add_on").value;
    
        document.getElementById("sub_total").value = isNaN(SubTotal) ? 0 : SubTotal;
    }
    
    
    document.getElementById("add_on").onchange = calculateSubTotal;
    document.getElementById("add_on").onkeyup = calculateSubTotal;
    document.getElementById("total_full").onchange = calculateSubTotal;
    document.getElementById("total_full").onkeyup = calculateSubTotal;
    document.getElementById("total_half").onchange = calculateSubTotal;
    document.getElementById("total_half").onkeyup = calculateSubTotal;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use Date() function in hibernate criteria, since one field is
I would like to add a field to the Django FlatPage database model, but
I would like to take a field and replace all characters that are not
I would like the text in the value field of a text box to
I would like to have a text field that a user can enter a
I would like to do the following: SELECT sum(max(field-10,000,0)) from TABLE as in, I
I would like to run something like: select * from table where field in
I would like to have access to the Seconds_Behind_Master field, (as returned by SHOW
I would like to overwrite the value of the password field before submiting a
I have a 'created_date' DATETIME field which I would like to be populated with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.