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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:17:41+00:00 2026-06-07T23:17:41+00:00

My code in HTML takes a user input number in, and it does a

  • 0

My code in HTML takes a user input number in, and it does a calculation and then displays the output. The user chosen input is put into a formula and the result of the formula is added to the user input number, but when it adds the two number together it’s adding a decimal spot.

For example, if the number 11 is chosen, the result of Rchange is 0.22, so .22 is then added 11 to be 11.22 for newResistance, but instead it is displaying the value as 110.22 instead.

function calc(form) {
    if (isNaN(form.resistance.value)) {
        alert("Error in input");
        return false;
    }
    if (form.resistance.value.length > 32) {
        alert("Error in input");
        return false;
    }
    var Rchange = .01 * 2 * form.resistance.value;
    var newResistance = (form.resistance.value + Rchange);
    document.getElementById("newResistance").innerHTML = chopTo4(newResistance);
}

function chopTo4(raw) {
    strRaw = raw.toString();
    if (strRaw.length - strRaw.indexOf("0") > 4) strRaw = strRaw.substring(0, strRaw.indexOf("0") + 5);
    return strRaw;
}
  • 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-07T23:17:43+00:00Added an answer on June 7, 2026 at 11:17 pm

    HTML DOM element properties are always strings. You need to convert them to numbers in your usage.

    parseInt(form.resistance.value);
    parseFloat(form.resistance.value);
    +form.resistance.value;
    

    (Any of the three will work; I prefer the first two (use parseInt unless you’re looking for a float).)

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

Sidebar

Related Questions

My html code to take two user chosen input numbers and do calculation. Trouble
So I have some code here that takes user input from a standard web
The program is supposed to take user input, turn it into html and pass
I'm writing a small piece of code which takes input from a user via
I have the following code: HTML <div id='foo'> <input type='checkbox' value='english' name='bar[english]' /> <input
I am creating a simple listbox filter that takes the user input and returns
I would like to have a custom snippet of html form code that takes
I'm writing a tiny program that takes user input using Getops, and based on
I have in my html code: <input class=hidd type=radio name=org1 value=1 /> <input class=hidd
I created a simple HTML form which takes input as username of the customer.

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.