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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:38:13+00:00 2026-06-18T14:38:13+00:00

l need help to finish my php project. l will like to have a

  • 0

l need help to finish my php project.
l will like to have a text fields V1,V2,V3 and result/output to accept only decimal numbers (4 decimal place ie 0.0000) or automatically turns numbers to four decimal pace and have a read-only field generate the total sum of the 3 text fields without reloading the form.

eg
text field v1+text field v2+text field v3=text field result

the text field should accept on four decimal numbers or automatically turn numbers to four decimal place.

I am using the following sum function;

function sum() 
{
    var TotalLBCReceipts = num("TotalLBCReceipts");
    var TotalKaaseReceipts = num("TotalKaaseReceipts");
    var TakoradiToFactory = num("TakoradiToFactory2");
    var KaaseToFactory = num("KaaseToFactory2");
    var SampleResidue = num("SampleResidue");
    var Sweepings  = num("Sweepings");
    var OrganicCocoa = num("OrganicCocoa2");
    var Confiscated = num("Confiscated");
    var Cuttings = num("Cuttings");
    var r = document.getElementById("GRANDTOTAL1");

    if (r != null) 
    {
         r.value = TotalLBCReceipts + 
                   TotalKaaseReceipts + 
                   TakoradiToFactory +
                   KaaseToFactory +
                   SampleResidue +
                   Sweepings +
                   OrganicCocoa +
                   Confiscated+Cuttings;
     }
}

And grabbing the Values using;

function num(id) 
{
    var e = document.getElementById(id);

    if (e != null) 
    {
        var v = e.value;
        if (/^\d+$/.test(v)) 
        {
            return parseInt(v, 10);
        }
    }

return 0;

}

thanks.

  • 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-18T14:38:14+00:00Added an answer on June 18, 2026 at 2:38 pm

    Google is your friend… As is StackOverflow!!

    You need to use JavaScript here, perhaps as well as PHP…

    Restrict to Numbers with decimal place:

    Restricting input to textbox: allowing only numbers and decimal point

    <HTML>
      <HEAD>
        <SCRIPT language=Javascript>
           <!--
           function isNumberKey(evt)
           {
              var charCode = (evt.which) ? evt.which : event.keyCode;
              if (charCode != 46 && charCode > 31 
                && (charCode < 48 || charCode > 57))
                 return false;
    
              return true;
           }
           //-->
        </SCRIPT>
      </HEAD>
      <BODY>
        <INPUT id="txtChar" onkeypress="return isNumberKey(event)" 
               type="text" name="txtChar">
      </BODY>
    </HTML>
    

    Sum Numbers with readonly field:

    adding the text box values and display it using javascript

    <form name="myFormName">
        <p><input type="text" name="myInputName1" value="25.3"></p>
        <p><input type="text" name="myInputName2" value="14.2"></p>
    </form>
    <div id="total"></div>
    
    <script type="text/javascript>
    
        var total = parseFloat(0, 10);
    
        total += parseFloat(document.myFormName.myInputName1.value, 10);
        total += parseFloat(document.myFormName.myInputName2.value, 10);
    
        document.getElementById("total").innerHTML = "Total is " + total;
    
    </script>
    

    Round to 4 Decimal Places;:

    https://stackoverflow.com/a/7269919/1305169

    Math.round(val*10000)/10000
    

    Hope this helps!

    EDIT:

    You need to change your Code to the following;

    Your sum Function:

    function sum() 
    {
        var TotalLBCReceipts = num("TotalLBCReceipts");
        var TotalKaaseReceipts = num("TotalKaaseReceipts");
        var TakoradiToFactory = num("TakoradiToFactory2");
        var KaaseToFactory = num("KaaseToFactory2");
        var SampleResidue = num("SampleResidue");
        var Sweepings  = num("Sweepings");
        var OrganicCocoa = num("OrganicCocoa2");
        var Confiscated = num("Confiscated");
        var Cuttings = num("Cuttings");
        var r = document.getElementById("GRANDTOTAL1");
    
        if (r != null) 
        {
             r.value = Math.round((
                           TotalLBCReceipts + 
                           TotalKaaseReceipts + 
                           TakoradiToFactory +
                           KaaseToFactory +
                           SampleResidue +
                           Sweepings +
                           OrganicCocoa +
                           Confiscated +
                           Cuttings) * 10000) / 10000;
         }
    }
    

    And your num function:

    function num(id) 
    {
        var e = document.getElementById(id);
    
        if (e != null) 
        {
            return Math.round(e.value*10000)/10000;
        }
    
        return 0;
    }
    

    You can probably just return the plain number from the num Function, however I show it here for completeness!

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

Sidebar

Related Questions

need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
Need help with a query that I wrote: I have three tables Company id
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need help with one ajax function This is raw page setup. Page will
need a small help to send an email to 2 email addresses on finish
I need a little help to solve the following question. I have two activities,
I have created a project for A User with Login Page. I need to
I need help on How to: Enable PCNTL in Ubuntu PHP. $ mkdir /tmp/phpsource
I almost have the data I want...but need help filtering it. (pic at bottom)

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.