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 8083689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:33:18+00:00 2026-06-05T17:33:18+00:00

I am trying to calculate the sub_total field based on: total_full + total_half. however

  • 0

I am trying to calculate the “sub_total” field based on:
“total_full” + “total_half”. however the javascript which i tried is not working. the result of sub_total is displaying as “0”.
How can I improve my javascript “calculate sub total” to allow me to add “total_full” and “total_half” together? ( I will then also implement the sub_total calculation to include “total_single”, “total_double”, and “total_projector” as well when I can get the calculation right.

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Conference Form</title>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jqueryui.js"></script>
<link href="style.css" rel="stylesheet" type="text/css"/>
<link href="css/jqueryui.css" rel="stylesheet" type="text/css" />

<body>

<div id="wrapper">
<div id="header"></div>

<table width="899" border="1" align="left" cellpadding="1">
  <form action="" method="get" name="myform">

  <tr>
    <td width="258"><label>Company Name</label></td>
    <td width="249"><input type="text" name="companyname" id="companyname" /></td>
    <td width="27">&nbsp;</td>
    <td width="186">Enquiry Date</td>
    <td width="145"><input type="text" name="enquiry_date" id="enquiry_date" class="datepicker" /></td>
  </tr>

  <tr>
    <td>Conference Date In</td>
    <td><input type="text" name="conference_date_in" id="conference_date_in" class="datepicker" /></td>
    <td>&nbsp;</td>
    <td>Conference Date Out</td>
    <td><input type="text" name="conference_date_out" id="conference_date_out" class="datepicker" /></td>
  </tr>
  <tr>
    <td>Total Days</td>
    <td><input type="text" name="total_days" id="total_days" /></td>
  </tr>
  <tr>
    <td>Number of Delegates</td>
    <td><input type="text" name="no_of_delegates" id="no_of_delegates" /></td>
    </tr>
   <tr>
    <td>Accommodation:</td>
    <tr>
    <td><p>Check in Date</p></td>
    <td><input type="text" name="check_in_date" id="check_in_date" class="datepicker" /></td>

    <td><p>Check out Date</p></td>
    <td><p>
      <input type="text" name="check_out_date" id="check_out_date" class="datepicker" />
        </p></td>
  </tr>
  <tr>
    <td>Total Days Accommodation</td>
    <td><input type="text" name="total_days_acc" id="total_days_acc" /></td>
  </tr>
  <tr>
    <td><strong>Contact Details</strong></td>
    </tr>
  <tr>
    <td>Contact Person</td>
    <td><input type="text" name="contact_person" id="contact_person" /></td>
    </tr>
  <tr>
    <td>Telephone Number</td>
    <td><input type="text" name="tel_no" id="tel_no" /></td>
    <td>&nbsp;</td>
    <td>Fax Number</td>
    <td><input type="text" name="fax_no" id="fax_no" /></td>
  </tr>
  <tr>
    <td>Cell Number</td>
    <td><input type="text" name="cell_no" id="cell_no" /></td>
    <td>&nbsp;</td>
    <td>Email</td>
    <td><input type="text" name="email" id="email" /></td>
  </tr>

  <tr>
    <td>Full Day Conference @ R260 p/p</td>
    <td><input type="text" name="full_day" id="full_day" />
    Full Days</td>
    <td>&nbsp;</td>
    <td>Total Cost Full Day</td>
    <td><input type="text" name="total_full" id="total_full" readonly="readonly" /></td>
  </tr>
  <tr>
    <td>Half Day Conference @ R240 p/p</td>
    <td><input type="text" name="half_day" id="half_day" />
    Half Days</td>
    <td>&nbsp;</td>
    <td>Total Cost Half Day</td>
    <td><input type="text" name="total_half" id="total_half" readonly="readonly" /></td>
  </tr>
  <tr>
    <td>Single Rooms @ R480 p/p</td>
    <td><input type="text" name="single_rooms" id="single_rooms" />
    Guests</td>
    <td>&nbsp;</td>
    <td>Total Cost Single Rooms</td>
    <td><input name="total_single" type="text" id="total_single" readonly="readonly" /></td>
  </tr>
  <tr>
    <td>Double / Twin Rooms @ R360 p/p/s</td>
    <td><input type="text" name="double_rooms" id="double_rooms" /> 
    Guests</td>
    <td>&nbsp;</td>
    <td>Total Cost Double / Twin</td>
    <td><input name="total_double" type="text" id="total_double" readonly="readonly" /></td>
  </tr>
  <tr>
    <td>Data Projector @ R400 rental p/day</td>
    <td><input type="text" name="data_projector" id="data_projector" /> 
      Days</td>
    <td>&nbsp;</td>
    <td>Total Cost Projector Rental</td>
    <td><input name="total_projector" type="text" id="total_projector" readonly="readonly" /></td>
  </tr>
   <tr>
    <td>Sub Total</td>
    <td><input name="sub_total" type="text" id="sub_total" readonly="readonly" /></td>
    </tr>
  <tr>
    <td height="23">&nbsp;</td>
    </tr>

  </form>
</table>

</div>

<div id="hideme">
Hello Hideme
</div>

</body>
</html>

JAVASCRIPT

<script type="text/javascript">
//Datepicker
$(function() {
    $(".datepicker").datepicker({ minDate: -0, maxDate: "+100M +10D",dateFormat: 'dd-mm-yy'})
    ({
        changeMonth: true,
        changeYear: true,
    });
        });

//Datepicker Enquiry Date Set to Today
var enquiry_date = $.datepicker.formatDate('dd-mm-yy', new Date());
document.getElementById('enquiry_date').value = enquiry_date;


//Datepicker Conference in / out
var calcDate = function() {
    var start = $('#conference_date_in').datepicker('getDate');
    var end = $('#conference_date_out').datepicker('getDate');
    var days = (end - start) / 1000 / 60 / 60 / 24 + 1;

    if(days==0) {days=1
    }
    if( days >= 0 ) {
    document.getElementById('total_days').value = days;
    } 
        }


$('#conference_date_out').change(calcDate);
$('#conference_date_in').change(calcDate);




//Datepicker Check in  / Out Accommodation
var calcDateAcc = function() {
    var startacc = $('#check_in_date').datepicker('getDate');
    var endacc = $('#check_out_date').datepicker('getDate');
    var daysacc = (endacc - startacc) / 1000 / 60 / 60 / 24;


    if(daysacc==0) daysacc=1
    if( daysacc >= 0 ) {
    document.getElementById('total_days_acc').value = daysacc;
    } 
        }


$('#check_in_date').change(calcDateAcc);
$('#check_out_date').change(calcDateAcc);



//Calculate Total Cost FullDay Conference
function calculateFull()
{
    var fulldays = parseInt(document.getElementById("full_day").value);

    var no_of_delegates = parseInt(document.getElementById("no_of_delegates").value);

    var fullprice = 260;

    var resultfull =  fulldays * no_of_delegates * fullprice;

    document.getElementById("total_full").value = resultfull;
    }

    $('#full_day').change(calculateFull).keyup(calculateFull);



//Calculate Half Day conference total   

    function calculateHalf()
{
    var halfdays = parseInt(document.getElementById("half_day").value);

    var no_of_delegates = parseInt(document.getElementById("no_of_delegates").value);

    var halfprice = 240;

    var resulthalf =  halfdays * no_of_delegates * halfprice;

    document.getElementById("total_half").value = resulthalf;
    }

    $('#half_day').change(calculateHalf).keyup(calculateHalf);



//Calculate Total Cost Single Rooms
    function calculateSingle()
{
    var single_rooms = parseInt(document.getElementById("single_rooms").value);

    var total_days_acc = parseInt(document.getElementById("total_days_acc").value);

    var single_rooms_price = 480;

    var resultsingle =  single_rooms * total_days_acc * single_rooms_price;

    document.getElementById("total_single").value = isNaN(resultsingle) ? 0 : resultsingle;
    }



    $('#single_rooms').change(calculateSingle).keyup(calculateSingle);
    $('#check_in_date').change(calculateSingle);
    $('#check_out_date').change(calculateSingle);





//Calculate Total Cost Double / Twin Rooms
    function calculateDouble()
{
    var double_rooms = parseInt(document.getElementById("double_rooms").value);

    var total_days_acc = parseInt(document.getElementById("total_days_acc").value);

    var double_rooms_price = 360;

    var resultdouble =  double_rooms * total_days_acc * double_rooms_price;

    document.getElementById("total_double").value = isNaN(resultdouble) ? 0 : resultdouble;
    }



    $('#double_rooms').change(calculateDouble).keyup(calculateDouble);
    $('#check_in_date').change(calculateDouble);
    $('#check_out_date').change(calculateDouble);




//Calculate Total Cost Date Projector
    function calculateProjector()
{
    var data_projector = parseInt(document.getElementById("data_projector").value);


    var data_projector_price = 400;

    var resultdata =  data_projector *  data_projector_price;

    document.getElementById("total_projector").value = isNaN(resultdata) ? 0 : resultdata;
    }



    $('#data_projector').change(calculateProjector).keyup(calculateProjector);





//Calculate Sub Total
    function calculateSubTotal()
{

    var SubTotal =  total_full +  total_half;

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


    $('#data_projector').change(calculateSubTotal).keyup(calculateSubTotal);







//Hide me Testing   
$("#full_day").keyup(function(){

        if ($('#full_day').val() == "1") {   
            $("#hideme").show("fast"); //Slide Down Effect
        }
        else {
            $("#hideme").hide("fast");    //Slide Up Effect
        }
    });
</script>
  • 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-05T17:33:20+00:00Added an answer on June 5, 2026 at 5:33 pm

    Does this do what you want :

    //Calculate Sub Total
        function calculateSubTotal()
    {
    
        var SubTotal =  +total_full.value +  +total_half.value;
    
        document.getElementById("sub_total").value = isNaN(SubTotal) ? 0 : SubTotal;
        }
    
    
    document.getElementById("total_half").onchange = calculateSubTotal;
    document.getElementById("total_half").onkeyup = calculateSubTotal;
    

    Note the use of unary + and .value when getting the values entered in total_full and total_half. Also the setting the of event handlers.

    Try it out here : http://jsfiddle.net/jstoolsmith/ue62p/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a shopping site and I am trying to calculate the
I am trying to calculate the zscore for a vector of 5000 rows which
Im trying to add a tax field. I have this working for whole numbers
Am trying to calculate the number of rows in a table depending on a
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am trying to calculate number of users, cumulatively for the dellstore2 database. Looking
I'm trying to calculate the time it takes to receive all data from a
I am trying to calculate a ranking of a team in an ordered MySQL
I am trying to calculate a position to place label on the screen. The
I'm trying to calculate elapsed hours between two times. When calculating PM to AM

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.