1

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).

1 Answer 1

2

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">

Sign up to request clarification or add additional context in comments.

2 Comments

cool it seems to work, but not when i use onchange="ln5cmpower('npml');convert1('NPML')" which is my main goal here. my variable naming is correct? how do i get multiple functions to function on change or on keyup?
Thank you for your help. I tested it a bit and I will use onkeyup="ln5cmpower('npml');convert1('NPML')" so that the user must only click input 2 field value and press enter to trigger the function instead of needing to click input field 2, change the value and press enter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.