Step by Step how to install java script effect for decimal allowed , you can follow instruction as below to implement in your website or blog :
<!-- TWO STEPS TO INSTALL DECIMALS ALLOWED:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkDecimals(fieldName, fieldValue) {
decallowed = 2; // how many decimals are allowed?
if (isNaN(fieldValue) || fieldValue == "") {
alert("Oops! That does not appear to be a valid number. Please 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 ("Oops! Please enter a number with up to " + decallowed + " decimal places. Please try again.");
fieldName.select();
fieldName.focus();
}
else {
alert ("That number validated successfully.");
}
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<center>
<form>
Please enter a number with up to 2 decimal places: <br>
<input type=text name=numbox>
<input type=button name=ok value="Ok" onClick="checkDecimals(this.form.numbox, this.form.numbox.value)">
</form>
</center>
<!-- Script Size: 1.42 KB -->
Home » FORM SCRIPT » DECIMALS ALLOWED JAVA SCRIPT
{ 0 comments... Views All / Send Comment! }
Post a Comment