Monday, November 22, 2010

List - Update Columns behind the screen based on other columns

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("populateFieldvalues");

    var populate = getField('select','Current Status');
    populate.onchange = populateFieldvalues;

    function populateFieldvalues() {
        var control = getField('select','Current Status'); //Based on the Value of this 'Current Status', Status &Description will be changed. Ex: If yellow is selected for 1 column, other column named Status, its URL and Desc would be changed accordingly.
        var Statusurl = getField('input', 'Status');
        var Statusdesc = getField('input', 'Description');

        if (control.options[0].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/white.gif";
            Statusdesc.value = "White";
            }
           
        else if (control.options[1].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/green.gif";
            Statusdesc.value = "Green";
            }

        else if (control.options[2].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/yellow.gif";
            Statusdesc.value = "Yellow";
            }
           
        else if (control.options[3].selected) {
            Statusurl.value = "http://YourServer/sites/SC1/SubSite1/ImageLibrary/red.gif";
            Statusdesc.value = "Red";
            }

        }

    function getField(fieldType,fieldTitle) {
           var docTags = document.getElementsByTagName(fieldType);
        for (var i=1; i < docTags.length; i++) {
            if (docTags[i].title == fieldTitle) {
                return docTags[i];
            }
           }
    }
   
</script>

No comments: