/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
jQuery.fn.moneyField = function(symbol) { return this.each(function() { $(this).focus(function(){ if(!$(this).val()) $(this).attr('value', symbol); }).blur(function(){ if($(this).val() == symbol) { $(this).attr('value', ''); } else { s = $(this).val(); s = $.numAddCommas(s); // Add commas to long digit strings - you will need to get a function to do this (find one on snipplr) $(this).attr('value', s); var hascur = s.indexOf(symbol); if(hascur) $(this).attr('value', symbol+s); } }).prev('label').click(function(){ return false; }); }); } $(function(){ $('input[name=money_field]').moneyField('£'); });