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

Question

Question

Limiting a field value based on another field

asked on July 18, 2018

I have a form that allows an approver to state how many hours a person has done on a particular activity. I need to restrict the value they enter so that it can't be higher than the maximum hours for that activity. The maximum hours value is in the first column pictured below...


I would think that JavaScript would be the answer but I am not sure how to get started on it.

 

Thanks in advance

0 0

Replies

replied on July 19, 2018

I was able to set the Max value for one field based on the value from another field by using the below JavaScript. Both fields are number fields. 

$(document).ready(function() {
  $('.FirstField').on("change", function(){
    var firstField = $('.FirstField input').val();
    $('.SecondField input').attr("max", firstField);
  });
})

 

0 0
replied on July 23, 2018

Hi @████████

Any idea how to make that work on a table ?

It kind of works but the FirstField value only comes from the first row in the table

 

Jonathan

0 0
replied on October 23, 2019 Show version history

Hello @████████,

I tried the script you provided above and it works perfectly anytime the FirstField (#q204) value is less than 1000. Once the FirstField value is equal to 1000 or more then it does not matter what value is entered in the SecondField (#q118), it will not accept any number. For example if the FirstField value equals 1500.00 and I enter 500.00 as the SecondField value it gives me an error that says "Value must be less than or equal to 1,500.00."

$(document).ready(function() {
  $('#q204').on("change", function(){
    var q204 = $('#q204 input').val();
    $('#q118 input').attr("max", q204);
  });
})
0 0
replied on October 23, 2019

Hi Christopher,

I am able to recreate your issue if the "Use thousands delimiter" checkbox is checked on the individual fields. If I un-check that box on both fields I do not get the error. 

1 0
replied on October 23, 2019

Thanks a million!

0 0
replied on June 22, 2020

Is there a way to accomplish this while retaining the thousands delimiter?

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

Sign in to reply to this post.