This is a working example of a three-way calculator made only with html and javascript. No jQuery or any other libraries required.
This is a working example of a three-way calculator made only with html and javascript. No jQuery or any other libraries required.
To handle different scenarios, we will use a series of “if” statements.
The calculator consists of three input boxes. If the field A, and ONLY if the field A is left empty, it will calculate it. Repeat the process for the field B and C.
The main function, “doDaMaths” is triggered either on clicking the green “calculate” button or hitting “Enter” key from any one of the input boxes.
To help users figure out how to use it, and to prevent confusion, there are two sets of error messages. If the user hits “Enter” with ALL THREE fields filled out, it says something in the lines of “It looks like you entered all three boxes!”. Another error message is triggered when there was no input saying, “Don’t forget to type in x2 fields”.
The result should. Look something like this:
Working example: http://calculate-things.com/percent.html
Editable code sample: https://codepen.io/LeoU/pen/BaBPNRr