Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

delicious read later bookmarklet

   1  
   2  javascript:delicious=window.open('https://api.del.icio.us/v1/posts/add?description='+encodeURIComponent(document.title)+'&tags=2read'+'&url='+window.location.href,'delicious','toolbar=no,width=50,height=50');setTimeout('delicious.close()',1500);

format brazilian money

   1  
   2  
   3  function FormataReais(fld, milSep, decSep, e) {
   4  		var sep = 0;
   5  		var key = '';
   6  		var i = j = 0;
   7  		var len = len2 = 0;
   8  		var strCheck = '0123456789';
   9  		var aux = aux2 = '';
  10  		var whichCode = (window.Event) ? e.which : e.keyCode;
  11  		if (whichCode == 13) return true;
  12  	 	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
  13  		if (strCheck.indexOf(key) == -1) return false;  // Chave inválida
  14  		len = fld.value.length;
  15  		for(i = 0; i < len; i++)
  16  		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) 
  17   		break;
  18   		aux = '';
  19   		for(; i < len; i++)
  20  		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  21  		aux += key;
  22  		len = aux.length;
  23  		if (len == 0) fld.value = '';
  24  		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  25  		if (len == 2) fld.value = '0'+ decSep + aux;
  26  		if (len > 2) {
  27  			aux2 = '';
  28   			for (j = 0, i = len - 3; i >= 0; i--) {
  29  				if (j == 3) {
  30  					aux2 += milSep;
  31  					j = 0;
  32  				}
  33  				aux2 += aux.charAt(i);
  34   				j++;
  35  			}
  36  			fld.value = '';
  37  			len2 = aux2.length;
  38  			for (i = len2 - 1; i >= 0; i--)
  39  			fld.value += aux2.charAt(i);
  40  			fld.value += decSep + aux.substr(len - 2, len);
  41  		}
  42  		return false;
  43  }


Then use in the form field:
   1  onkeypress="return(FormataReais(this,'.',',',event))"
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS