I would like to input a formula in an input field, then onblur the formula I just typed will calculate and return the result in the same field, replacing the formula.
ex. inputing 2+2 gets replaced with 4 onblur or inputing (8*4)+3 gets replaced with 35.
I'd like to use the class to bind the script so I can use it on multiple fields. Is there a command or function I need to call to tell jquery that I want to calculate the contents of the single input? I found 50 answers about calculating multiple input boxes, but not 1 answer about using just a single input field for everything.
UPDATE: I've revised my jQuery to work with eval, though that is considered super dangerous and I can't actually use it. But seeing it work at least was optimistic.
I also deleted the link to my fiddle because as was pointed out, jsfiddle isn't loading any jquery libraries so it will never work on there.
<html>
<input id='formula_and_total' class='self_calculate'>
</html>
$(document).ready(function() {
$('input.self_calculate').on('blur', function() {
//let formula = $ (input, this).val ();
let formula = $(this).val();
//let formula = document.getElementById ('formula_and_total').value;
$(this).val(eval(formula));
});
});