Validation rule - One field is great then another

Validate that one form field value is greater than another.

Overview

The issue is that ChronoForms lacks a built-in validation rule to compare two numeric fields.
Add a custom JavaScript validation function and apply it to the second field's validation rules.

Answered
ChronoForms v6
ha har7801 06 Aug, 2021
Is there a code that can validate that one field is greater then another.

I have a mileage start field and a mileage end.

Want to validate the end is entered greater than the start field.

Thanks

fields are mileage_start and mileage_end
Gr GreyHead 06 Aug, 2021
Hi har7801,

I don't see anything built in to CFv6 to do this but this FAQ suggests a way to add custom JavaScript and/or PHP validation.

Bob
teldrive teldrive 07 Aug, 2021
Answer
Following examples of Bob, this worked for my
(inside of multifield areas i have insterted one "javascript custom code" with this function
jQuery.fn.form.settings.rules.customfn = function() {
field1=document.getElementById("field1").value;
field2=document.getElementById("field2").value;
let result = (field1 < field2) ? true:false;
return result;
};
and in validation rules of field2
customfn: Error message because field2 must be greater than field1
that works fine, thanks Bob
teldrive teldrive 07 Aug, 2021
just to add in validation rules of field2
This topic is locked and no more replies can be posted.