i know there is an answer to this in shareponit 2013 and that SharePoint Online/365 should be pretty much the same, however i can't seem to get the following code (not my own, this is taken from a StackExcange Answer ) to work
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
//get the ProjectName from they query string
var ProjectName = getParameterByName("ProjectName");
//Set the corresponding Lookup field value to the Contact ID
$("select[Title='ProjectName']").val(ProjectName);
//use this line to disable the lookup field selection
$("select[Title='ProjectName']").attr('disabled','disabled')
//use this line to hide the lookup field and label entirely
//$("select[title='ProjectName']").closest("tr").hide();
});
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
I am manually for now adding a URL "/NewForm.aspx?ProjectName=Test2" for example
Test2 (no spaces) is available from my lookup drop down list
Checked the source of my new form page to make sure i had the right field name
<!-- FieldName="ProjectName"
FieldInternalName="ProjectName"
FieldType="SPFieldLookup"
-->
I also used the Jquery file both from a library in my own site and directly from the source in the above code
Any help would be appreciated.
alert ('Project Name Is: '+ProjectName);
to the script and the alert is returning the correct project name, the problem now is setting that ProjectName Val to my field ProjectName
– Paul Jul 14 '16 at 16:08