Javascript
<!-- Script by hscripts.com -->
<!-- copyright of HIOX INDIA -->
<!-- more scripts @ http://www.hscripts.com -->
<script language=javascript>
function checkDecimals(fieldName, fieldValue)
{
decallowed = 2;
if (isNaN(fieldValue) || fieldValue == "")
{
alert("Not a valid number.try again.");
fieldName.select();
fieldName.focus();
}
else
{
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
if (dectext.length > decallowed)
{
alert ("Enter a number with up to " + decallowed + "decimal places. try again.");
fieldName.select();
fieldName.focus();
}
else
{
alert ("Number validated successfully.");
}
}
}
</script>
<!-- Script by hscripts.com -->
HTML Code
<!-- Script by hscripts.com -->
<form name="frm">
Enter a number with up to 2 decimal places:<br>
<input type=text name="txt">
<input type=button name=ok value="Ok" onclick="checkDecimals(this.form.txt, this.form.txt.value)"><br><br>
<div align=right>©<a href="http://www.hscripts.com" style="color: #3D366F;text-decoration:none;cursor:pointer;font-size:13px;">hscripts.com</a></div>
</form>
<!-- Script by hscripts.com -->
Release Date - 07-04-2008
Get free version without ©copyright link for just
5
|