Load predefined data from columns and update field with possible selection with Javascript

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3143682%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3ELoad%20predefined%20data%20from%20columns%20and%20update%20field%20with%20possible%20selection%20with%20Javascript%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3143682%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CP%3E%3CSPAN%3EI%20am%20struggling%20with%20piece%20of%20code.%20I%20am%20working%20on%20SharePoint%202013%20and%20I%20am%20trying%20to%20set%202%20fields%20fixed%20when%20creating%20a%20new%20item%20in%20list.%20All%203%20fields%20are%20lookup%20columns%2C%20but%20the%20red%20highlighted%20fields%20I%20want%20to%20set%20as%20fixed%20and%20the%20yellow%20highlighted%20field%20is%20conditioned%20by%20the%20field%26nbsp%3B%26lt%3B%5C%2FSPAN%26gt%3B%3CSTRONG%3EVyberova_Skupina_Sluzba%26lt%3B%5C%2FSTRONG%26gt%3B%3CSPAN%3E%26nbsp%3BAlso%26nbsp%3B%26lt%3B%5C%2FSPAN%26gt%3B%3CSTRONG%3EVyberova_Skupina_Sluzba%26lt%3B%5C%2FSTRONG%26gt%3B%3CSPAN%3E%26nbsp%3Bis%20conditioned%20by%20the%20field%26nbsp%3B%26lt%3B%5C%2FSPAN%26gt%3B%3CSTRONG%3EVyber_Oblast%26lt%3B%5C%2FSTRONG%26gt%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F346750i5669B915ED9E3A3E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22vyber.JPG%22%20alt%3D%22%5C%26quot%3Bvyber.JPG%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FSTRONG%26gt%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EI%20used%20the%20part%20of%20the%20code%20below%2C%20the%20fields%20are%20fixed%26nbsp%3B%3CSTRONG%3EVyber_Oblast%26lt%3B%5C%2FSTRONG%26gt%3B%26nbsp%3Band%26nbsp%3B%3CSTRONG%3EVyberova_Skupina_Sluzba%26lt%3B%5C%2FSTRONG%26gt%3B%26nbsp%3Bbut%20third%20column%20is%20not%20updated.%26lt%3B%5C%2FP%26gt%3B%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3CPRE%20class%3D%22%5C%26quot%3Blia-code-sample%22%20language-javascript%3D%22%22%3E%3CCODE%3Efunction%20nastavSluzba()%7B%5Cn%20%20%20%20%24(%5C'%23Produktova_Skupina_Sluzba%5C').find(%5C'select%5C').val(%5C'Hypotek%C3%A1rne%20%C3%BAvery%5C')%3B%20%20%20%20%5Cn%20%20%20%20%24(%5C'%23Vyber_Oblasti%5C').find(%5C'select%5C').val(%5C'%C3%9Averov%C3%A9%20produkty%20pre%20FO%5C')%20%20%20%20%20%20%20%5Cn%20%20%20%20%20%20%20%20%24(%5C'%23tableNapoveda%5C').remove()%3B%5Cn%20%20%20%20%20%20%20%20%24(%5C%22%23Vyber_Oblasti%5C%22).find(%5C'select%5C').attr(%5C%22disabled%5C%22%2C%20true)%3B%5Cn%20%20%20%20%20%20%20%20%24(%5C%22%23Produktova_Skupina_Sluzba%5C%22).find(%5C'select%5C').attr(%5C%22disabled%5C%22%2C%20true)%3B%5Cn%20%20%20%20%20%20%20%20%24(%5C%22%23Vyber_Oblasti%5C%22).find(%5C'select%5C').css(%7B%5C%22background-color%5C%22%3A%20%5C%22white%5C%22%2C%5C%22color%5C%22%3A%20%5C%22black%5C%22%7D)%3B%20%5Cn%20%20%20%20%20%20%20%20%24(%5C%22%23Produktova_Skupina_Sluzba%5C%22).find(%5C'select%5C').css(%7B%5C%22background-color%5C%22%3A%20%5C%22white%5C%22%2C%5C%22color%5C%22%3A%20%5C%22black%5C%22%7D)%3B%5Cn%20%20%20%20%20%20%20%20%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5Cn%5Cn%5Cnvar%20allOptions%20%3D%20document.querySelectorAll(%5C%22%5Btitle%3DVyber_Oblasti%5D%20option%5C%22)%3B%5Cn%5Cn%5B%5D.some.call(allOptions%2C%20function(option)%20%7B%5Cn%20%20%20%20if%20(option.innerHTML%20%3D%3D%20%5C%22%C3%9Averov%C3%A9%20produkty%20pre%20FO%5C%22)%20%7B%5Cn%20%20%20%20%20%20%20%20option.selected%20%3D%20%5C%22%C3%9Averov%C3%A9%20produkty%20pre%20FO%5C%22%3B%5Cn%20%20%20%20%20%20%20%20return%20true%3B%5Cn%20%20%20%20%7D%5Cn%7D)%3B%5Cn%5Cn%5Cnvar%20allOption%20%3D%20document.querySelectorAll(%5C%22%5Btitle%3DProduktova_Skupina_Sluzba%5D%20option%5C%22)%3B%5Cn%5Cn%5B%5D.some.call(allOption%2C%20function(option)%20%7B%5Cn%20%20%20%20if%20(option.innerHTML%20%3D%3D%20%5C%22Hypotek%C3%A1rne%20%C3%BAvery%5C%22)%20%7B%5Cn%20%20%20%20%20%20%20%20option.selected%20%3D%20%5C%22Hypotek%C3%A1rne%20%C3%BAvery%5C%22%3B%5Cn%20%20%20%20%20%20%20%20return%20true%3B%5Cn%20%20%20%20%7D%5Cn%20%20%20%20%5Cn%7D)%3B%26lt%3B%5C%2Fcode%26gt%3B%26lt%3B%5C%2Fpre%26gt%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ECan%20you%20help%20me%20make%20sure%20that%20the%20third%20field%20is%20loaded%20automatically%20and%20that%20the%20user%20can%20select%20an%20option%20that%20falls%20under%26nbsp%3B%26lt%3B%5C%2FSPAN%26gt%3B%3CSTRONG%3EProduktova_Skupina_Sluzba%26lt%3B%5C%2FSTRONG%26gt%3B%3CSPAN%3E%26nbsp%3B%3F%26lt%3B%5C%2FSPAN%26gt%3B%26lt%3B%5C%2FP%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3CLINGO-LABS%20id%3D%22%5C%26quot%3Blingo-labs-3143682%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CLINGO-LABEL%3Ecss%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3EDesigner%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3EDeveloper%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3Ehtml%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3EJavaScript%26lt%3B%5C%2Flingo-label%26gt%3B%26lt%3B%5C%2Flingo-labs%26gt%3B%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E
Occasional Contributor

I am struggling with piece of code. I am working on SharePoint 2013 and I am trying to set 2 fields fixed when creating a new item in list. All 3 fields are lookup columns, but the red highlighted fields I want to set as fixed and the yellow highlighted field is conditioned by the field Vyberova_Skupina_Sluzba Also Vyberova_Skupina_Sluzba is conditioned by the field Vyber_Oblast

 

vyber.JPG

 

I used the part of the code below, the fields are fixed Vyber_Oblast and Vyberova_Skupina_Sluzba but third column is not updated.

 

function nastavSluzba(){
    $('#Produktova_Skupina_Sluzba').find('select').val('Hypotekárne úvery');    
    $('#Vyber_Oblasti').find('select').val('Úverové produkty pre FO')       
        $('#tableNapoveda').remove();
        $("#Vyber_Oblasti").find('select').attr("disabled", true);
        $("#Produktova_Skupina_Sluzba").find('select').attr("disabled", true);
        $("#Vyber_Oblasti").find('select').css({"background-color": "white","color": "black"}); 
        $("#Produktova_Skupina_Sluzba").find('select').css({"background-color": "white","color": "black"});
        
                


var allOptions = document.querySelectorAll("[title=Vyber_Oblasti] option");

[].some.call(allOptions, function(option) {
    if (option.innerHTML == "Úverové produkty pre FO") {
        option.selected = "Úverové produkty pre FO";
        return true;
    }
});


var allOption = document.querySelectorAll("[title=Produktova_Skupina_Sluzba] option");

[].some.call(allOption, function(option) {
    if (option.innerHTML == "Hypotekárne úvery") {
        option.selected = "Hypotekárne úvery";
        return true;
    }
    
});

 

Can you help me make sure that the third field is loaded automatically and that the user can select an option that falls under Produktova_Skupina_Sluzba ?

0 Replies