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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:08:33+00:00 2026-05-23T10:08:33+00:00

I found [this][1], rather difficult, javascript example online and I’ve implemented it with success

  • 0

I found [this][1], rather difficult, javascript example online and I’ve implemented it with success in my website.

However, I would like to get the result of, in this case, the two subtotals in one new text-field.

The traditional getElementbyId and total.value=total didn’t work out.

EDIT

 function doMath()
{
    // Capture the entered values of two input boxes
    var twogiga = document.getElementById('twogig').value;
    var fourgiga = document.getElementById('fourgig').value;

    // Add them together and display
    var sum = parseInt(twogiga) + parseInt(fourgiga);
    document.getElementById('total').value = parseInt(sum);
}

This is the javascript I use. But for some reason, when I have just one value (twogig), the total is set as NaN. What is wrong with my 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-05-23T10:08:33+00:00Added an answer on May 23, 2026 at 10:08 am

    Well, if you have assigned ID’s to text inputs, for example: <input type=”text” id=”my_input” />, then you can call it with document.getElementById(‘my_input’).value.

    So:

    <input type="text" id="my_input1" />
    <input type="text" id="my_input2" />
    <input type="button" value="Add Them Together" onclick="doMath();" />
    
    <script type="text/javascript">
        function doMath()
        {
            // Capture the entered values of two input boxes
            var my_input1 = document.getElementById('my_input1').value;
            var my_input2 = document.getElementById('my_input2').value;
    
            // Add them together and display
            var sum = parseInt(my_input1) + parseInt(my_input2);
            document.write(sum);
        }
    </script>
    

    Naturally, that is a very basic script, it doesn’t check to make sure the entered values are numbers. We have to convert the fields into integers, otherwise they’ll be strings (so 2+2 would equal 22). When the button is clicked, the function is called, which makes a variable for each input box, converts them to ints, adds them, and outputs our sum.

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

Sidebar

Related Questions

Found this rather strange bug in IE8; element.style.top is limited to 1342177 pixels. Even
I always found this rather annoying fact about applets, that they disappear if you
I found this snippet of SQL in a view and I am rather puzzled
This is my first post on this rather spiffing website so go easy on
I have found this post on Erlang and CUDA, it is rather old so
I've found a couple online services that do this, and I found this post
I found this wonderful example of pulling data from a Google spreadsheet in JSON:
I found this code on the website http://rosettacode.org/wiki/Closest-pair_problem and I adopted the C# version
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can

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.