Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing two inputs fields with three functions for one output
    text
    copied!<p>I use two functions to process two inputs and then have a third function to compare the results with the result of the third function being the output. </p> <p>Here is my HTML:</p> <pre><code>&lt;form id="standardPremuimcalc" oninput="updateOutput()"&gt; &lt;input name= "new_loan_amount" type="number" value="0"/&gt; &lt;input name= "purchase_price" type="number" value="0"/&gt; &lt;output name= "premuim_rate" for="new loan amount purchase price"&gt;&lt;/output&gt; &lt;/form&gt; </code></pre> <p>Here is my js:</p> <pre><code>function updateOutput(){ var form = document.getElementById("standardPremiumcalc"); var out = form.elements["premium_rate"]; var amount = parseInt(form.elements["new_loan_amount"].value); var purchase = parseInt(form.elements ["purchase_price"].value); var loanCalc = lender() var ownCalc = owner() function lender(amount){ if (amount&lt;=100000){ if (amount&lt;=40000){ return 200; }else{ return (Math.ceil(amount/1000))*5; } }else{ if ((amount-100000)&lt;=500000){ return 500+(Math.ceil((amount-100000)/1000)*3.95); }else if ((amount-500000)&lt;=2000000) { return 2080+(Math.ceil((amount-500000)/1000)*2.65); }else{ return 6055+(Math.ceil((amount-2000000)/1000)*2); } } } function owner(purchase) { if (purchase&lt;=100000){ if (purchase&lt;=40000){ return 200; }else{ return (Math.ceil(purchase/1000))*5; } }else{ if ((purchase-100000)&lt;=500000){ return 500+(Math.ceil((purchase-100000)/1000)*3.95); }else if ((purchase-500000)&lt;=2000000) { return 2080+(Math.ceil((purchase-500000)/1000)*2.65); }else{ return 6055+(Math.ceil((purchase-2000000)/1000)*2); } } } function standardPremium (loanCalc,ownCalc) { if (loanCalc-ownCalc&gt;0) { out.value = loanCalc+ownCalc }else{ out.value = loanCalc } } lender(amount) owner(purchase) standardPremium(loanCalc,ownCalc) }; </code></pre> <p>I am not getting an output field, what am I missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload