Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************
- * calculable textfield
- *
- * usage: $('.calculable').calculable();
- ******************************************/
- (function ( $ ) {
- $.fn.calculable = function()
- {
- this.keydown(function(event){
- if ( event.which === 61 ) { //keycode 61 is the equals sign =
- var string = $(this).val().replace(',','.').replace(/[^0-9.+\-\/\*]/g,'');
- var calculated = eval(string);
- if(typeof calculated !== 'undefined') {
- $(this).val(calculated);
- }
- event.preventDefault();
- }
- });
- return this;
- };
- }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement