I'm a beginner in JavaScript/jQuery and I am designing my first app using jQuery Mobile.
It is a basic calculator used for spectroscopic calculations.
I have 3 fields: You enter your values in the first and second field and I compute a number that appears in the third field. I used the keyup
function to have real-time calculations performed.
The feature I would like to add is after the calculation is performed and appears in the third field that you can modify the third field to see the second field change (it would do the inverse calculation. The first field would remain the same)
What is the best way to do this in JavaScript? In my example I performed my inverse calculation but don't know how to display it back.
HTML
<div data-role="content" class="page11" >
<div data-role="fieldcontain">
<label for="l0">Excitation</label>
<input type="text" name="l0" id="l0" data-clear-btn="true" value="">
<label for="l1">Signal</label>
<input type="text" name="l1" id="l1" data-clear-btn="true" value="">
<label for="l2">Shift</label>
<input type="text" name="l2" id="l2" data-clear-btn="true" value="">
</div>
Javascript
$('input').keyup(function () {
var l0 = parseFloat($('#l0').val()) || 0;
var l1 = parseFloat($('#l1').val()) || 0;
var dw1 = (l0 * l1)/2 || 0;
var dw = dw1.toFixed(2);
document.getElementById("l2").value = dw;
/* Inverse calculation */
var dw2 = parseFloat($('#l3').val()) || 0;
var l1_22 = 2 * dw2 / l0;
var l1_2 = l1_22.toFixed(2);
});
Thank you