Rounding in Javascript
If anyone can help resolve a real headache in writing a javascript that will round correctly, I would be so very much appreciative! I am very new at writing Javascript, but I am getting better and more creative all of the time. Right now, I am absolutely stumped. I'm designing form, and I've run into an issue with writing a javascript with validation. Here is the situation:
1. I have three columns. The first column is a number which is input by the person filling out the form. As an example they might enter $75,480 into column one.
Column 2 and column 3 are numbers to be entered by the person filling out the form.
2. Column 2: Since column 2 is a number input by the person filling out the form, I wrote a validation script as follows:
var a = this.getField("Q5").value;
if (event.value > a)event.value="";
else event.value;
Q5 is a hidden field that I wrote that is a value based on $75,480 x 0.01 = $754.80.
I wrote the validation so the number enter in column 2 does not exceed 1% of $75,480. Also, the result in Column 2 has no decimals so the result would be $755. If someone enters $754.80 into the field the result would be $755. However, if the person enters $755 into the field the value goes blank because it exceeds the $754.80.
I can't figure this out with my simple programming skills. I feel like the answer is to have the validation result be a whole number $755 and not the $754.80. I'm assuming if the validation were equal to the rounded number then I would get a result in column 2.
3. Column 3 is the same situation with a different percent multiplied. I'm thinking if I can resolve Column 2 situation i will be able to write the validation for Column 3.
THANK YOU in advance for any feedback.
Sincerely,
Steve
