... or if you wanted to round up or down to the nearest 10...
Code:
<html>
<head>
</head>
<body>
Enter Quantity 1: <input type="text" name="red" />
Enter Quantity 2: <input type="text" name="blue" />
Enter Quantity 3: <input type="text" name="green" />
<script type="text/javascript">
els=document.getElementsByTagName("input")
for (var i = 0; i < els.length; i++) {
if (els[i].type=="text"){
els[i].onblur=function(){this.value=checkVal(this.value)}
}
}
function checkVal(box){
return Math.round(box*0.1)/0.1;
}
</script>
</body>
</html>
or if you wanted to be sneaky and only round up...
Code:
<html>
<head>
</head>
<body>
Enter Quantity 1: <input type="text" name="red" />
Enter Quantity 2: <input type="text" name="blue" />
Enter Quantity 3: <input type="text" name="green" />
<script type="text/javascript">
els=document.getElementsByTagName("input")
for (var i = 0; i < els.length; i++) {
if (els[i].type=="text"){
els[i].onblur=function(){this.value=checkVal(this.value)}
}
}
function checkVal(box){
while (box%10!=0) {
box++
}
return(box);
}
</script>
</body>
</html>
Bookmarks