This content has been marked as final.
Show 3 replies

1. Re: If box is > 100 or < 0 how do I 0 out that box?
evil8 Nov 25, 2008 10:25 AM (in response to (Brad_Grasty))You want your script to read:
If the current field value is less than 0 OR the current field value is greater than 100 then the current field value is equal to 0.
Try this:
if (event.value < 0  event.value > 100){
event.value = 100;
} 
2. Re: If box is > 100 or < 0 how do I 0 out that box?
gkaiseril Nov 25, 2008 11:02 AM (in response to (Brad_Grasty))Make sure you have spelled and captilalized your field names exactly the same as the fields. You may also need to set the field calculation order.
Are there any messages in the JavaScirpt Debugging console?
I would have used the custom calculation script, as this field will be recalculcated when any field involved in a calculation is updated, while the 'validation' action only occurs when a field has data entered into the field from the keyboard.
And you can use either:
event.value = this.getField("Factor_Weight_1").value;
if (this.getField("Factor_Weight_Total").value > 100) event.value = 0;
if (this.getField("Factor_Weight_Total").value < 0) event.value = 0;
// or
event.value = this.getField("Factor_Weight_1").value;
if (this.getField("Factor_Weight_Total").value < 0  this.getField("Factor_Weight_Total").value > 100) event.value = 0;
In the 'Custom Calculation Script'. 
3. Re: If box is > 100 or < 0 how do I 0 out that box?
(Brad_Grasty) Nov 25, 2008 12:26 PM (in response to (Brad_Grasty))Ok I check the capitalization and that is correct. The JavaScript Debugging is very happy with the syntax and throws no errors.
event.value = this.getField("Factor_weight_1").value;
if (this.getField("Factor_weight_total").value < 0  this.getField("Factor_weight_total").value > 100) event.value = 0;
I have put the script in the validation and in the calculation field both times when I type in anything the field 0s out.
The script Gene Dianoski posted will check the current field but not make sure that the total is < 100 so I edited it
if (this.getField("Factor_weight_total").value < 0  this.getField("Factor_weight_total").value > 100){
event.value = 0;
}
This works once I got the script in the validate section.
In the calculation field I had to get Factor_weight_1 to sum itself (so it really did not do anything.) This let me set the calculation order to Factor_weight_total and then Factor_weight_1
Now it will 0 itself out if the total is 100 or more.
The problem now is if my Factor_weight_total = 90 and I set Factor_weight_1 that is currently 0 to 15 the Factor_Weight_total = 105and it is happy.
If I then go back to Factor_Weight_1 and set it as 20 because Factor_weight_total = 105 it sets Factor_Weight_1 to 0
Could I use something like a pre addition check validation?
if (this.getField("Factor_weight_total").value + this.getField("Factor_weight_2") < 0  this.getField("Factor_weight_total").value + this.getField("Factor_weight_2") > 100){
event.value = 0;
}