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

  • Home
  • SEARCH
  • 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 446119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:26:21+00:00 2026-05-12T21:26:21+00:00

Thanks for the responses.. i put a live version of the code.. to see

  • 0

Thanks for the responses.. i put a live version of the code.. to see if that helps resolve this. It is here:

http://www.zacharydesigns.com/sandbox/calculatorJS.html

I updated the following code to reflect what was offered as an answer.. however this just returns zero

I am having trouble wrapping my head around creating a simple equation in javaScript. What I am trying to achieve is to have a=(x/z)*y.

x = user input
z = total of all input
y = defined number (in this case 300)

What I came up with is

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript">
function update()
{
    var a = $("#productOne").val(); // '#' identify IDs as in CSS
    var b = $("#productTwo").val();
    var c = $("#productThree").val();
    var productTotal = Math.floor(a/(a+b+c));
    $("#productTotal").val(productTotal); // Set calculated value in the HTML
}

</script>

<form name="calc" action="#">
    <table align="center" border="1">
        <tr>
                <td align="right">
                        Product One:
                </td>
                <td align="left">
                        <input type="text" name="productOne" id="productOne" size="5" /></td>
                <td align="right">
                        Product Two:
                </td>
                <td align="left">
                        <input type="text" name="productTwo" id="productTwo" size="5" /></td>
                <td align="right">
                        Product Three:
                </td>
                <td align="left">
                        <input type="text" name="productThree" id="productThree" size="5" /></td>
        </tr>
        <tr>
                <td colspan="2" align="center">
                        <input type="button" value="Calculate" onclick="update();return false;" />
                </td>
        </tr>
        <td align="right">
                Product Total:</td>
        <td align="left">
                <input type="text" name="productTotal" id="productTotal" size="6" readonly="readonly" /></td>
        </tr></table>
</form>

which I am not sure is even close. Can someone help guide me through this, please?

  • 1 1 Answer
  • 1 View
  • 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-05-12T21:26:21+00:00Added an answer on May 12, 2026 at 9:26 pm

    I see a couple of things that are not working in your script:

    • The year variable is not used and there is no year input in your form.

    • The a, b and c variable declaration, I think that you want to get the values from your input elements.

    • You assign the calculation to the productTotal variable, and later you use the undefined theProductTotal variable.

    To get the form elements by name I would recommend you something like this:

    function update() {
      var a = +document.forms['calc'].elements['productOne'].value,
          b = +document.forms['calc'].elements['productTwo'].value,
          c = +document.forms['calc'].elements['productThree'].value,
          productTotal = Math.floor(a/(a+b+c)*300);
    
      document.forms['calc'].elements['productTotal'].value = productTotal;
    
      return false;
    }
    

    Notice how I’m getting the input values, since you are using only the name attribute, you can access the elements in that way.

    Also look that I’m converting the input values to Number (by using the unary plus operator), since the value property is string, and that can give you problems when you sum, because if you use the add operator with strings a concatenation will take place.

    Check the above example here.

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

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add
Thanks for reading this. I am dynamically generating some data which includes a select
Thanks for a solution in C , now I would like to achieve this
Thanks to a library upgrade (easymock 2.2 -> 2.4), we're having tests that have
Thanks for reading this. I have markup similar to what is below. Using the
I want to use a temp directory that will be unique to this build.
Thanks to a Q&A on stackoverflow. I just found out how to determine the
Thanks for reading. I'm a bit new to jQuery, and am trying to make
Thanks for answers,Actually I am not puzzled about draw 1024*768 pixels is slower than

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.