$('input').keyup(function(){ // run anytime the value changes
// get value of field
// convert it to a float
var oil = Number($('#oil').val()); //Oil
var sap = Number($('#sap').val()); //Oil's SAP Value
var sfp = Number($('#sfp').val()); //SuperFat %
var eop = Number($('#eop').val()); //Essential Oil %
//calcs
var ph = oil * sap;
var sh = ph * 0.713;
var water = sh * 2;
var sbw = sh + oil;
var sf = sbw * (sfp / 100);
var sbwf = sbw + sf;
var eo = sbwf * (eop / 100);
var tbw = oil + sh + water + sf + eo;
document.getElementById('ph').value = ph.toFixed(2).replace(/\.00$/, '');
document.getElementById('sh').value = sh.toFixed(2).replace(/\.00$/, '');
document.getElementById('water').value = water.toFixed(2).replace(/\.00$/, '');
document.getElementById('sbw').value = sbw.toFixed(2).replace(/\.00$/, '');
document.getElementById('sf').value = sf.toFixed(2).replace(/\.00$/, '');
document.getElementById('eo').value = eo.toFixed(2).replace(/\.00$/, '');
document.getElementById('tbw').value = tbw.toFixed(2).replace(/\.00$/, '');
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.