Problem with hiding 2 SharePoint fields with javascript/jQuery

Problem with hiding 2 SharePoint fields with javascript/jQuery

I have some code which i've got which hides 2 SharePoint fields based on the values of the said fields. 

I have 2 fields. 'Service Lead Approved?' and 'Funding Request Sanctioned?'. Both are boolean (yes/no) fields.
The code checks to see if the values of 2 fields are set to specific values and then hides either one or both fields from view dependant on their values.

Everything works as normal for 2 of the 3 outcomes.

IF 'Service Lead Approved?' and 'Funding Request Sanctioned?' both equal 'NO', then 'Funding Request Sanctioned?' is hidden.

IF 'Service Lead Approved?' equals 'YES' and 'Funding Request Sanctioned?' equals 'NO', then 'Funding Request Sanctioned?' is hidden.

However, when 'Service Lead Approved?' and 'Funding Request Sanctioned?' both equal 'YES', then 'Service Lead Approved?' IS hidden but 'Funding Request Sanctioned?' is not. In my code, both fields should be hidden and I cannot see why this isn't working.

Any help would be greatly appreciated.











  1. <!-- SECTION 4.0: SHOW/HIDE 'SERVICE LEAD APPROVED'/'FUNDING REQUEST SANCTIONED?' OPTIONS -->
  2. // since we will be accessing the collection of nobr elements multiple times,
  3. // let's cache the collection for performance.
  4. var nobr;
  5. // define globally, set in document ready function (see below)
  6.  
  7. function showConditionalRows() {
  8.       var okToShow = true;
  9.       var hideALL = true;
  10.       if ($("select[title='Service Lead Approved?']").val() == "Yes" && $("select[title='Funding Request Sanctioned?']").val() == "Yes") {
  11.             hideALL = false;
  12.       }
  13.       else if ($("select[title='Service Lead Approved?']").val() == "No" && $("select[title='Funding Request Sanctioned?']").val() == "No") {
  14.             okToShow = false;
  15.       }
  16.       else if ($("select[title='Service Lead Approved?']").val() == "Yes" && $("select[title='Funding Request Sanctioned?']").val() == "No") {
  17.             okToShow = false;
  18.       }
  19.       // set up an array with the display names of the conditional fields
  20.       var titles1 = ['Funding Request Sanctioned?'];
  21.       var titles2 = ['Funding Request Sanctioned?','Service Lead Approved?'];
  22.       for (var i = 0; i < titles1.length; i++) {
  23.             nobr.filter(":contains('" + titles1[i] + "')").closest("tr").toggle(okToShow);
  24.       }
  25.       for (var i = 0; i < titles2.length; i++) {
  26.             nobr.filter(":contains('" + titles2[i] + "')").closest("tr").toggle(hideALL);
  27.       }
  28. }
  29. $(document).ready(function() {
  30.       // initialize global vars
  31.       nobr = $("nobr");
  32.       showConditionalRows();
  33.       $("select[title='Service Lead Approved?'], select[title='Funding Request Sanctioned?']").change(function() {
  34.             showConditionalRows();
  35.       });
  36. });