Advertisement
Guest User

Untitled

a guest
May 27th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. /******************************************
  2. * calculable textfield
  3. *
  4. * usage: $('.calculable').calculable();
  5. ******************************************/
  6. (function ( $ ) {
  7. $.fn.calculable = function()
  8. {
  9. this.keydown(function(event){
  10. if ( event.which === 61 ) { //keycode 61 is the equals sign =
  11. var string = $(this).val().replace(',','.').replace(/[^0-9.+\-\/\*]/g,'');
  12. var calculated = eval(string);
  13. if(typeof calculated !== 'undefined') {
  14. $(this).val(calculated);
  15. }
  16. event.preventDefault();
  17. }
  18. });
  19. return this;
  20. };
  21. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement