user55
07-18-2007, 05:16 PM
Hi,
I hope somebody can help me with this. I have a form that auto calculates a number of fields. I want to get the last field which is "field4" to round to the nearest (500th) whole number. For example, if the value in "field4" is 3655 then I want it to automatically round it to 3500.
What ever the amount is, I want it to be automatically rounded to the nearest 500. For example:
500
1000
1500
2000
2500
3000 and so on
Here is what I have so far:
<html>
<head>
<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
qty = document.myform.qty.value;
document.myform.field1.value = (qty * 500);
document.myform.field2.value = (qty * 20);
amt = document.myform.field3.value;
document.myform.field4.value = (amt * 9.5);
}
function stopCalc(){
clearInterval(interval);
}
</script>
</head>
<body>
<form name="myform" method="post" action="go" onsubmit="return check(this)" />
<input type="text" name="qty" value="" onfocus="startCalc();" onblur="stopCalc();" />
<input type="text" name="field1" /><br />
<input type="text" name="field2" />
<!--end first calculations-->
<input type="text" name="field3" value="530" onfocus="startCalc();" onblur="stopCalc();" />
<input type="text" name="field4" value="" />
<input type="button" value="submit" />
</form>
</body>
</html>
Hope all of this makes sense. Thanks!
Regards,
Sara
I hope somebody can help me with this. I have a form that auto calculates a number of fields. I want to get the last field which is "field4" to round to the nearest (500th) whole number. For example, if the value in "field4" is 3655 then I want it to automatically round it to 3500.
What ever the amount is, I want it to be automatically rounded to the nearest 500. For example:
500
1000
1500
2000
2500
3000 and so on
Here is what I have so far:
<html>
<head>
<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
qty = document.myform.qty.value;
document.myform.field1.value = (qty * 500);
document.myform.field2.value = (qty * 20);
amt = document.myform.field3.value;
document.myform.field4.value = (amt * 9.5);
}
function stopCalc(){
clearInterval(interval);
}
</script>
</head>
<body>
<form name="myform" method="post" action="go" onsubmit="return check(this)" />
<input type="text" name="qty" value="" onfocus="startCalc();" onblur="stopCalc();" />
<input type="text" name="field1" /><br />
<input type="text" name="field2" />
<!--end first calculations-->
<input type="text" name="field3" value="530" onfocus="startCalc();" onblur="stopCalc();" />
<input type="text" name="field4" value="" />
<input type="button" value="submit" />
</form>
</body>
</html>
Hope all of this makes sense. Thanks!
Regards,
Sara