I have a calendar app created in SharePoint 2013, I want to Autofill Location text field in popup window of add new event.
How can I do it with help of JavaScript or jQuery?
Follow below steps:
Go to New form page of calendar list form using URL in below format:
https://siteUrl/Lists/ListName/newform.aspx
Edit the page
Add Script editor/Content editor web part on page
Add below code in web part to auto-populate the Location field on form:
<script type="text/javascript">
function autoPopulateLocation(){
// your code
document.querySelector("input[title^='Location']").value = "My custom value";
}
_spBodyOnLoadFunctionNames.push("autoPopulateLocation");
</script>
_spBodyOnLoadFunctionNames.push("autoPopulateLocation");
Output:
Update from comments:
To disable the textbox, use below code:
document.querySelector("input[title^='Location']").disabled = "disabled";
OR with readonly attribute like:
document.querySelector("input[title^='Location']").readOnly = true;
readOnly approach from updated answer.