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?
Question
Question
JavaScript to Validate a Number Range Based on a Drop-down Field Selection
Answer
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); } }); })
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!
Replies
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.