Category Archives: jquery
`calculable’ textboxes using jquery
Here’s some code to make your textboxes calculable. Demonstration here. (function($) { $.fn.calculable = function() { return this.each(function() { $(this).focus(function(e) { var expr = $(this).attr('calcExpr'); if (expr) { $(this).val(expr); } }); // end focus $(this).blur(function(e) { try { var expr = $(this).val(); var calculated = eval('with(Math){'+expr+'}'); $(this).attr('calcExpr', expr); $(this).val(calculated); } catch (e) { $(this).attr('calcExpr', ''); [...]
Using javascript to avoid the mouse and page scrolling