Kamis, 01 April 2010

Disable All element

HTML code :







CSS Code :


#disablingDiv
{
/* Do not display it on entry */
display: none;

/* Display it on the layer with index 1001.
Make sure this is the highest z-index value
used by layers on that page */
z-index:1001;

/* make it cover the whole screen */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 1000px;

/* make it white but fully transparent */
background-color: silver;
opacity:.50;
filter: alpha(opacity=50);
font-weight:bold;
}



JavaScript Code :



function disableAllElement() {
document.getElementById('disablingDiv').style.display='block';
}

Kamis, 11 Maret 2010

Validasi Angka dengan JavaScript


Buat input box, dan masukkan code > onkeyup="checkNumber(this)"
di dalamnya.

function checkNumber(obj) {
/* obj merupakan referensi dari input box */

var strPass = obj.value;
/* ambil value dari object input box */

var strLength = strPass.length;
/* cek panjang value dari input box */

var lchar = obj.value.charAt((strLength) - 1);
/* ambil inputan paling akhir dari input box*/

var cCode = CalcKeyCode(lchar);
/* panggil function CalcKeyCode untuk me-return key code
javascript*/

if(cCode < 48 || cCode > 57){/*cek key code angka atau bukan*/
var myNumber = obj.value.substring(0, (strLength) - 1);
obj.value = myNumber;
}
return false;
}

function CalcKeyCode(aChar) {
var character = aChar.substring(0, 1);
var code = aChar.charCodeAt(0);
return code;
}