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

Question

Question

JavaScript to Validate a Number Range Based on a Drop-down Field Selection

asked on January 1, 2018

Below is the JavaScript that is currently being used to validate a number field range, Hours Per Week, based on the Employment Status radio button field selection being Full Time, or another selection.  How would I modify the JavaScript if I wanted to use a drop-down field, instead of a radio button?

JavaScript for Validating Hours Per Week Field Based on Employment Status Radio Button Field Selection.png
0 0

Answer

SELECTED ANSWER
replied on January 1, 2018

Hi John,

You could update your script like this:

$(document).ready(function(){
  $('.EmploymentStatus select').change(function(){
    if ($(this).val() == 'Full Time') {
      $('.PayType select').attr('disabled', false);
    }
    else {
      $('.PayType select').attr('disabled', true);
    }
  });
})

 

2 0
replied on January 2, 2018

Thanks, Rui, for providing the script update which reflects the change in the code when using a Drop-down field, instead of a Radio Button field.  Below is a print screen of the entire code.  Because the Pay Type field would still be shown whether or not the Employment Status field choice is Full Time or Part Time (it only limits the Pay Type field to Hourly and does not include Salary as a choice if Hours per Week is less than 30, I'm not sure if John Catano's solution would produce the same results.  Knowing John's expertise, it probably does.  However, since I already had the script, it was just quicker to have it modified.  Thanks to both of you for your answers!

JavaScript for Validating Hours Per Week Field Based on Employment Status Drop-down Selection.png
Employment Status Fields.png
Pay Data Fields.png
0 0

Replies

replied on January 2, 2018

Hi John,

Rui's change will work fine, just change them to selects.

Another option, because I try to avoid javascript for simple items like this, is to just have a second field with your alternate options. Then, in field rules, show which ever Hours Per Week selection is allowed based on your selection in employment status.

 

 

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

Sign in to reply to this post.