简体   繁体   中英

How can I display two results in a JavaScript calculator?

I am building this little calculator where there is only one input field and when user submits the data, I want form to do 2 calculations and display the results in separate divs.

In the first div, I want to whatever user puts in the input area and multiply it by 0.017 (result goes into first div). For the second calculation, I want to multiply the whatever value was put into the input field by 0.170 and display the result in a separate div. Please see the image for visual rep.

在此处输入图片说明

Essentially you are creating two values (one calculation for each field) then setting the inside of the display elements (the DIVs) to the values of the calculations:

var someNumber = 10;
var someNumberAfterCalculationOne = someNumber % 4;
var someNumberAfterCalculationTwo = someNumber - someNumberAfterCalculationOne;

document.getElementById("lt_input").innerHTML = someNumberAfterCalculationOne;
document.getElementById("kg_input").innerHTML = someNumberAfterCalculationTwo;

Here is an example of how you might accomplish this:

http://jsfiddle.net/nmbwamtd/3/

This approach is a little ugly, but should get you through to the next step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM