Pages

Wednesday, August 18, 2010

Only Decimal values in javascript

Following is the code for only decimal allowed in javascript .

Javascript Code :-



function onlyDemialValues(objEvent, id) {


var iKeyCode;
if (window.event) // IE
{
iKeyCode = objEvent.keyCode;
}
else if (objEvent.which)  // Netscape/Firefox/Opera
{
iKeyCode = objEvent.which;
}
if (iKeyCode >= 48 && iKeyCode <= 57 || iKeyCode == 46 || iKeyCode == 8) {

if (iKeyCode == 46) {
if (document.getElementById(id).value.indexOf(".") != -1) return false;
}

return true;
}
return false;
}

Related Other posts

3 comments: