Using jQuery to show/hide a field based on 2 dropdown fields

Discussion in 'jQuery' started by Rick Lister, May 8, 2013.

  1. #1
    Hi everyone,
    Ive got a jQuery script which shows a SharePoint field based upon a dropdown value. This is great but I need to modify it so that I can show a field if 2 dropdown values are matched. Ive tried a few different ways but I cannot for the life of me get it to work.
    Im only learning jQuery so am more than likely falling down here.
    The current code to hide 1 or more SharePoint fields based on 1 dropdown is:
    <!-- SECTION 1.0: SHOW 'RESPOND WITHIN 7 DAYS' OPTION -->
    // since we will be accessing the collection of nobr elements multiple times,
    // let's cache the collection for performance.
    var nobr;
    // define globally, set in document ready function (see below)
     
    function showConditionalRows(show) {
        // set up an array with the display names of the conditional fields
        var titles = ['Information request formally responded to within 7 days'];
     
        for (var i = 0; i < titles.length; i++)
            nobr.filter(":contains('" + titles[i] + "')").closest("tr").toggle(show);
    }
     
    // cache the 'STATUS' select control
    var sltStatus;
     
    $(document).ready(function() {
        // initialize global vars
        nobr = $("nobr");
        sltStatus = $("select[title='Status']");
     
        var val = sltStatus.val();
        showConditionalRows(val == "Completed");
       
        // add code to update visibility of conditional rows when project status changes
        sltStatus.change(function() {
          // if the value is "Completed", show all fields.
            var val = $(this).val();
            showConditionalRows(val == "Completed");
        });
    });
    Code (markup):
    So basically here, if 'STATUS' = 'Completed' then it shows the 'Information request formally responded to within 7 days' field. As I said, this works great, but.....
    I would like to change the code so that if 'STATUS' = 'Completed' and 'PLANNED WORK' ='Unplanned' then it shows the 'Information request formally responded to within 7 days' field
    Any help would be appreciated

    Rick
    -=stylus=-
     
    Rick Lister, May 8, 2013 IP
  2. HowDoYou

    HowDoYou Well-Known Member

    Messages:
    443
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #2
    If you post up the rest of your code with some example GUI, then i'll fix it for you.
     
    HowDoYou, May 10, 2013 IP