CSS Opacity or Transparency in Mozilla,IE, and Opera

No Comments

To make an HTML item, transparent in your web page, you need to add a below class into your css and apply it on your item page.

<style type=”text/css”>
.alpha50 {opacity:.50;filter: alpha(opacity=50); -moz-opacity: 0.5;}
</style>

javascript parseDecimal number format with decimal

No Comments

Want a number_format function or decimal display in javascript, try this

function parseDecimal(d, zeros, trunc) {
d=d.replace(/[a-zA-Z\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\|\[\]\\\:\"\;'\<\>\?\,\/\~\`]/g,"");
while (d.indexOf(".") != d.lastIndexOf("."))
d=d.replace(/\./,"");
if (typeof zeros == 'undefined' || zeros == "") {
return parseFloat(d);
} else {
var mult = Math.pow(10,zeros);
if (typeof trunc == 'undefined' || (trunc) == false)
return parseFloat(Math.round(d*mult)/mult);
else
return parseFloat(Math.floor(d*mult)/mult);
}
}

Javascript ForEach Equivalent – JS

No Comments

One thing with the For Loop in JavaScript is it doesn’t seem to be very well documented that you can use it to do an equivalent of a ForEach loop.

Here’s a short example of doing the ForEach loop equivalent in JavaScript:

var colors = ['Red','Green','Blue'];

for ( var i in colors )
{
alert( colors[i] );
}

In the above code, the variable "i" is our iterator and by using the "in" keyword the "for" loop actually loops through all elements in the Array for us. Using this you no longer have to worry about the length of the array.

var_dump in Javascript – debug your JS script

No Comments

As a PHP user, you would love var_dump function. But how would you use it in Javascript? Here is some function that can help you to debug your JS:

/* ====== START FUNCTION ===== */
function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}
/* ====== END FUNCTION ===== */

Or if you like to use print_r then you may try this function:

/* ====== START FUNCTION ===== */
function print_r(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
		var value = arr[item];

		if(typeof(value) == 'object') { //If it is an array,
			dumped_text += level_padding + "'" + item + "' ...\n";
			dumped_text += dump(value,level+1);
		} else {
			dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
		}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
/* ====== END FUNCTION ===== */

Hope this can help you out.

How to remove yellow background from Google Autofill in your web form

No Comments

For web developer

The best way is using CSS (Cascading Style Sheets) by adding background colour for your form field with !important.

For example:

<style type=”text/css”>
input {background-color: #FFF !important;}
</style>

Newer Entries