0

I have applied cascading between two columns for ex: Country column and Capital column. Now for every country in first column we have one capital in second column. If I select India then I have two options in second column as:-

  • None
  • Delhi

and then the user has to select delhi from second column. So what I need is When user selects country from first column the Capital column should be populated automatically. What is the possible way of doing this?

6
  • How do you map Country and Capital? Meaning did you save them in lists? Provide some information about the list. Commented Dec 7, 2015 at 6:37
  • Make the capital a mandatory field, it should remove 'None option (assuming it is a lookup column). Or, why can't you remove 'None' when you filter it based on Country?
    – Prakash
    Commented Dec 7, 2015 at 6:42
  • Yes as the fellow developers are saying make capital column mandatory. Commented Dec 7, 2015 at 6:50
  • I don't see any option for lookup column to make it required field. But I tried with JQuery. $( ":input[title='Country']" ).change(function() { $(":input[title='States']"); $(":input[title='States']").find("option[value='0']").remove(); }); It works for me when I tried it directly writing it in browser Console area but when I added it to content editor then the function is not running on change of country column
    – KumarV
    Commented Dec 7, 2015 at 7:46
  • 1
    Perhaps your content editor code is running before the field is rendered on the form. Try running it after form load is finished.
    – Prakash
    Commented Dec 7, 2015 at 9:07

1 Answer 1

2

If you are pulling the values from a different list, you can do this with the following code. This uses REST API, jQuery, ajax. The setup is a form with an Agent drop down. When they select the agent's name, it pulls in additional data stored in a contact list and populates those fields on the form. The populated fields are text fields. Seems like this would work for what you are asking since it looks like there will only be one cascading value per each drop down value.

$(document).ready(function(){
$(".input").change(function(){
var agent = $("#agentName").val();
$.ajax({
        url: "_api/web/lists/getbytitle('My List Name')/items?$filter=((Title eq '"+agent+"' ))",
        type: "GET",
        dataType: "json",
        headers: {
        Accept: "application/json;odata=verbose"
        },
    success: function(data) {
        $.each(data.d.results, function(index, item) {
            $("#g_cf9022f4_d084_49f1_b9bd_59c8fd5cf398_ff5_new_ctl00_ctl00_TextField").val(item.Team);
        $("#g_cf9022f4_d084_49f1_b9bd_59c8fd5cf398_ff2_new_ctl00_ctl00_TextField").val(item.Email);
        $("#g_cf9022f4_d084_49f1_b9bd_59c8fd5cf398_ff1_new_ctl00_ctl00_TextField").val(item.Title);
        });
    },
    error: function(error){
        alert(JSON.stringify(error));
    }  
});
});
);    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.