How to: Set default values in a SharePoint new form using javascript/jQuery

SharePoint does not allow you to set default values for multi text and rich text fields.

This article describes how to set default values in a rich text field using jQuery. You can use the code to set the default description in an inviting calendar event.

1. Edit the new form and add a content editor webpart.

2. Paste the following script code:

<script src="/_layouts/Sapiens.at.SharePoint/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script>
 
<script src="/_layouts/spjs-utility.js" type="text/javascript"></script>
 
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
function fillDefaultValues(){
// Set the value for description
setFieldValue('Description','<DIV><DIV> </DIV><DIV> </DIV><DIV><STRONG>Kind Regards,</STRONG></DIV><DIV>Firstname Lastname</DIV><DIV>Mail: <A href="mailto:firstname.lastname@domain.zone">firstname.lastname@domain.zone</A></DIV><DIV>Phone: +43 1 23619030</DIV><DIV> </DIV></DIV>', false);
}
 
</script>
<script src="/_layouts/Sapiens.at.SharePoint/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script>

<script src="/_layouts/spjs-utility.js" type="text/javascript"></script>

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
function fillDefaultValues(){
// Set the value for description
setFieldValue('Description','<DIV><DIV> </DIV><DIV> </DIV><DIV><STRONG>Kind Regards,</STRONG></DIV><DIV>Firstname Lastname</DIV><DIV>Mail: <A href="mailto:firstname.lastname@domain.zone">firstname.lastname@domain.zone</A></DIV><DIV>Phone: +43 1 23619030</DIV><DIV> </DIV></DIV>', false);
}

</script>

JQuery-1.6.2 is included in the sapiens.at SharePoint Framework V 2.2. You can also download jQuery from jquery.com – don’t forget to change the source path above in this case.

3. Download spjs-Utility.js and place it into your ../LAYOUTS folder. Follow the link below to download the file.

Many thanks to Alexander Bautz and his article on how to Get or set value for SharePoint field in NewForm, EditForm and DispForm (get only in DispForm). The required js files can be downloaded there.