Sigh I do not see many errors when checking here in solutions, so I thought I would send another ...
// locate all the input fields on the page $(':input') // bind to anything change related (down to keyboard changes so the element // won't need to lose focus, or the user won't have to press enter) .bind('keypress keydown keyup change',function(){ // retrieve the values of the inputs (we also call parseFloat to confirm // we are dealing with numeric values) var acho = parseFloat($(':input[name="acho"]').val(),10), alto = parseFloat($(':input[name="alto"]').val(),10), matl = parseFloat($(':input[name="material"]').val(),10); // default the end result to an empty string (you'll see // why with the following statement) var v = ''; // confirm that all three values that go in to the equation are // all numbers before we try to perform any math functions. If // all goes well, "v" above will have the actual resulting value. // if any number is invalid, the "Result" field (ml) gets emptied if (!isNaN(acho) && !isNaN(alto) && !isNaN(matl)){ // your math function v = (matl / 100) / ((alto / 100) * (acho / 100)); } // replace the value of "ml" with our new calculated value $(':input[name="ml"]').val(v.toString()); });
... with a demo
source share