Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73935

how can I make a field's value one hundredth of what is actually entered?

$
0
0

Currently, when you click the submit button, it'll multiply the number in the first field by the number in the second field.

What I want is to get the number in the second field to calculate as 1/100th of whatever the user enters.

For example, if you were to enter 1000 in the first field, and 6 in the second field, then the calculation would execute as 1000 * 0.06 instead of 1000 * 6, resulting in 60 instead of 6000.

I ask because simply entering in 0.0X in the second field causes the answer to be zero, which is obviously incorrect.

Except, I have no idea what I need to write to get it to work. What can I add/change in my JavaScript?

const submitButton = document.getElementById('submitButton');

submitButton.addEventListener('click', () => {
    const numberOne = document.getElementById('numberOne').value;
    const numberTwo = document.getElementById('numberTwo').value;
    const mathSolution = parseInt(numberOne) * parseInt(numberTwo);
    alert("The solution is... " + mathSolution);

}); 
<h2>Enter a number</h2><input type="number" id="numberOne"><h2>Enter another number</h2><input type="number" id="numberTwo"><button type="submit" id="submitButton">Calculate</button>

Viewing all articles
Browse latest Browse all 73935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>