Linked selection fields via client-side scripting

I have a need for my users to choose one field from a dropdown in Opportunity, then have another field limited in choices based on the first selection. I thought I had found the perfect guide from Greytrix here - http://www.greytrix.com/blogs/sagecrm/2014/09/11/linked-selection-fields-through-client-side-scripting/

I followed it while substituting my own values. However, the sub selection is not being updated based on the first selection. My picture should help explain, but basically each of the Main selection (Markets) in have a code of A or B or C etc. Each of the Sub Selections (Product) has a code of A1 or A2 or B1 or B2 etc. I simply substituted my values, saved to the Custom Content in the Opportunity Detail Screen. But it still isn't working. Thoughts on this?

Thanks!

Parents
  • 0

    There are two items associated with a SELECT object; value (the item that is submitted to the database) and text (displayed on screen). I think you are mixing these in your script. Try the following, which uses the value of the 'Markets' SELECT to filter the 'Products' SELECT by value.

    $(document).ready(function(){

    var options = $("#oppo_products").html();

    $("#oppo_markets").change(function(){

    $("#oppo_products").html(options);

    if (this.value.length){

    $('#oppo_products :not([value^="' + this.value + '"])').remove();

    if ($("#oppo_products").val() == $("#_HIDDENoppo_products").val()){

    $("#oppo_products").append("-None-");

    }else{

    $("#oppo_products").append("-None-");

    }

    }

    })

    $("#oppo_markets").trigger("change");

    })

    It is assumed that the 'Products' SELECT OPTION values are prefixed with the 'Markets' SELECT values, eg

    Code, Translation

    Markets:

    'Agri_', 'Agriculture'

    'EandU_', 'Energy and Utilities'

    'AirP_', 'Air Pollution and Control'

    'FandB_', 'Feed and Beverage'

    etc..

    Products:

    'Agri_Fertilizer', 'Fertilizer'

    'EandU_GasOil', 'Gas and Oil'

    'Agri_Herbicide', 'Herbicide'

    'AirP_AirScrubber', 'Air Scrubber'

    etc..

Reply
  • 0

    There are two items associated with a SELECT object; value (the item that is submitted to the database) and text (displayed on screen). I think you are mixing these in your script. Try the following, which uses the value of the 'Markets' SELECT to filter the 'Products' SELECT by value.

    $(document).ready(function(){

    var options = $("#oppo_products").html();

    $("#oppo_markets").change(function(){

    $("#oppo_products").html(options);

    if (this.value.length){

    $('#oppo_products :not([value^="' + this.value + '"])').remove();

    if ($("#oppo_products").val() == $("#_HIDDENoppo_products").val()){

    $("#oppo_products").append("-None-");

    }else{

    $("#oppo_products").append("-None-");

    }

    }

    })

    $("#oppo_markets").trigger("change");

    })

    It is assumed that the 'Products' SELECT OPTION values are prefixed with the 'Markets' SELECT values, eg

    Code, Translation

    Markets:

    'Agri_', 'Agriculture'

    'EandU_', 'Energy and Utilities'

    'AirP_', 'Air Pollution and Control'

    'FandB_', 'Feed and Beverage'

    etc..

    Products:

    'Agri_Fertilizer', 'Fertilizer'

    'EandU_GasOil', 'Gas and Oil'

    'Agri_Herbicide', 'Herbicide'

    'AirP_AirScrubber', 'Air Scrubber'

    etc..

Children
No Data