You are viewing limited content. For full access, please sign in.

Question

Question

Restricting a Number Field based on Another Number Field's Input

asked on July 21, 2020

Is it possible to restrict the max value of a number field based on the value (calculated via formulas) from another number field?

I have a series of simple add and subtract calculations to determine the max amount of money an employee can contribute to their Health Savings Account per year. When they choose how much they'd like to deposit per year into that account, I'd like to be able to restrict it to the value that was determined by those calculations.

For the sake of discussion, 

Max Contribution per Year = Field A

Elected Contribution per Year = Field B

I'd like to be able to limit the value of Field B to that of Field A, which is calculated via a formula. I'm sure there's some JavaScript to accomplish this, I'm just not sure where to begin. Any suggestions?

0 0

Replies

replied on July 23, 2020

I'm not sure if this is what you want, but below is a very rudimentary JavaScript solution that will change the maximum value of FieldB to the value of FieldA when FieldA is changed:

 

$(document).ready(function(){

  // When the value of FieldA is changed
 $( "#FieldA" ).change(function() {
   
   // Set the maximum value of FieldB to the value of FieldA
   $("#FieldB").attr("max",$( "#FieldA" ).attr("value"));

 });
});

 

1 0
replied on July 30, 2020

Hey Stephen,

Sorry I'm just now getting around to responding to this. If I'm understanding that code correctly, it will only apply upon the change of FieldA? Is there any way to modify this to apply from the outset, perhaps on document load, and not upon changing FieldA?

The scenario is basically calculating the maximum value for someone based on their age. They're asked to input their age as of 10/1/2020 and if they're 55+, the value of FieldA changes, but if they're not, it stays the same as it is upon loading the form.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.