lens calculator lens calculator - 4 months ago 16
HTML Question

Variable Naming Grammar HTML/ JavaScript

How do I properly send values from two HTML input fields
into a JavaScript function, which displays a value into
a third final HTML input field?

What do I have to change to get this to work?
I am sure it is the function names and variable values
not getting sent to the function.

I have this input field we'll call input 0(dbel):

<input type="number" id="dbel" value="1" step="0.1" min="0">


I have this field input 2(npml) here:

<input id="npml" onkeyup="convert1('NPML')" onchange="ln5cmpower('npml')">


This is the function which determines input 3 rounded to the nearest hundredth;
input3 = ((1/.05) + (1/ -(input2 - (input0/100))))

function ln5cmpower(npml, dbel) {
powerln5cm = ((1/.05)+(1/-(document.getElementById("npml").value-(document.getElementById("dbel").value/100))));
document.getElementById("POWERln5cm").value = Math.round(powerln5cm*100)/100;
}


And here is input 3, which will display final results that don't go anywhere else.

<input id="POWERln5cm">


Input 2 already may determine, and may be determined by, input 1,
which is what function convert1 is for.

Function convert1 works fine so I suppose I may ignore it.
The part that doesn't work is function ln5cmpower, from what I can tell.

Once a value shows up in input 2(npml),
this field will trigger function ln5cmpower to
determine the value of input 3(POWERln5cm) using the value of
input 2(npml) and input 0(dbel) once a value shows up in input 2(npml).

Answer

Your code is working fine, I assembled your code to make a working demo. Although the function you called on keyup event onkeyup="convert1('NPML')" is missing that throws an exception when entering values to input fields preventing the output of your onchange event.

function ln5cmpower(npml, dbel) {
    powerln5cm = ((1/.05)+(1/-(document.getElementById("npml").value-(document.getElementById("dbel").value/100))));
    document.getElementById("POWERln5cm").value = Math.round(powerln5cm*100)/100;
}
<input type="number" id="dbel" value="1" step="0.1" min="0">
<input id="npml"  onchange="ln5cmpower('npml')">
<input id="POWERln5cm">

Comments