Hello Mohamed El-Qassas
good the see the solution, i have create a list for test it, but nothing happen. could you help check what is wrong ?
<script language="javascript" src="
https://2016sps.com/sites/SharePoint/SiteAssets/jquery%20files/jquery-1.10.2.min.js"></script>
<script language="javascript">
$(document).ready(function () {
// Set the lookup field name in the new form
var LookupField= $("input[title='Employee']");
LookupField.change(function () { PopulateLookupField(); });
});
var ListItem;
function PopulateLookupField() {
// Set the lookup field name in the new form
var LookupField = $("input[title='Employee']").val();
if(LookupField)
{
var clientContext = new SP.ClientContext.get_current();
//set lookup list name
var LookupList = clientContext.get_web().get_lists().getByTitle('Employeelist');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq> <FieldRef Name=\'Employee\' /> <Value Type=\'Text\'>' + LookupField + '</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>');
ListItem = LookupList.getItems(camlQuery);
clientContext.load(ListItem);
clientContext.executeQueryAsync(Function.createDelegate(this,this.Succed),Function.createDelegate(this,this.Failed));
}
}
function Succed(sender, args) {
if(ListItem.get_count()>0)
{
var item = ListItem.getItemAtIndex(0);
// Text
$("input[title='Name']").val(item.get_item('Name'));
}
else
{
// text
$("input[title='Name']").val('');
alert("There is no match !");
}
}
function Failed(sender, args) {
alert('Error. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
it will report error: one or more field types are not installed properly ......