Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

How to populate a text field on a NewForm based on a Column lookup selection?

$
0
0

Hi Guys,

I have these Lists.

Lists

Columns

Lookup Column

Supplier

Name, EmailAddress

 

Initiator

Company, EmailAddress

Company > Name of Suppier’s List

 

How can I display the EmailAddress of Supplier’s List in the EmailAddress text field of Initiator’s List whenever its corresponding company is selected?

I have tried to using this code from this post (thanks to the author) on my NewForm but I can seem to get this working. Maybe I’m doing something wrong here.  I’m not a programmer actually so I’m looking forward guys for your advice.

<script type="text/javascript" src="/TestSubsite/Scripts/jquery-1.6.2.js" language="javascript"></script><script type="text/javascript" src="/TestSubsite/Scripts/jquery.SPServices-0.7.2.min.js" language="javascript"></script><script type="text/javascript" language="javascript">


$(document).ready(function() {
 $().SPServices.SPDisplayRelatedInfo({ 
 
columnName: "Company", 
relatedList: "Suppliers", 
relatedListColumn: "Name", 

relatedColumns: ["EmailAddress"],
displayFormat: "list", 
//Hide Column Headers and the data output from original function, not using the function as originally designed 
//headerCSSClass: "ms-hidden", 
//rowCSSClass:"ms-hidden", 
completefunc: SetFields,
debug: true
  });
}); 
function SetFields(){ 
          var srcDivId = "SPDisplayRelatedInfo_Terms";
          var tds = document.getElementById(srcDivId).getElementsByTagName("td");
          var Column1Data = tds[0].innerHTML; 
          var theDropDown = getTagFromIdentifierAndTitle("select","","Company");  
           var theTextBox = getTagFromIdentifierAndTitle("input","","EmailAddress"); 
           //This is what prevents it from being changed every time the page flips.
            if (theTextBox.value==""){ 
              theTextBox.value = Column1Data;  
                         } 
          else if (theTextBox.value!==Column1Data){          
                     theDropDown.parentElement.onclick = function(){   
                      theTextBox.value = Column1Data;
                           }; 
          }     
              };
function getTagFromIdentifierAndTitle(tagName, identifier, title) { 
          var len = identifier.length;   
        var tags =   document.getElementsByTagName(tagName);     
      for (var i=0; i <   tags.length; i++) {   
        var tempString = tags[i].id;           
    if (tags[i].title == title && (identifier == "" ||   tempString.indexOf(identifier) == tempString.length - len)) {   
            return tags[i];       
         }           
 }         
  return null;         
          };</script>

By the way, we are on SharePoint Foundation 2010 and just using SharePoint Designer if that would help.

Thanks in advanced,

Arnel


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>