1

SP2010

Have an edit form, with a multiple choice column titled [Required] that is set as display. I'm trying to use jquery to hide certain columns based on the value of Required.

Example. If "Required" equals A, then hide columns "B", "C", if equals B, hide "A", "C", etc.

The following script works but only if Required is in edit mode (assuming because of '.change(function'. I can't figure out how to get the value of Required when it's in display mode. Here is the script I currently have:

$(document).ready(function() {
    var $a = $('.a').closest('tr').hide();
    var $b = $('.b').closest('tr').hide();
    var $c = $('.c').closest('tr').hide();    

    $("select[title='Required']").change(function() {         
        var selectedValue = $(this).val();

        if(selectedValue  === 'a') {
            $c.hide();            
            $b.hide();
            $a.show();
        } else if (selectedValue === 'b') {
            $c.hide();            
            $a.hide();
            $b.show();
        } else if (selectedValue === 'c') {
            $b.hide();           
            $a.hide();
            $c.show();  

        } else {
            $a.hide();
            $b.hide();
            $c.hide();           
        }
    });
}); 
  • Have y tried having the $("select[title='Required']").change(function() { outside the document. ready? – XristosK Nov 4 '14 at 17:40
  • Just tried it and no luck, although it could be that I wrote it incorrectly. – David Nov 6 '14 at 20:33
  • Start by opening console or use firebug. Then, put a console.log inside the $("select[title='Required']").change(function(). If it does't show, then in firebug/command prompt, write aa = $("select[title='Required']") and then write aa, to see if yr selection is correct – XristosK Nov 7 '14 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.