Set default value of multiple lines of text (enhanced rich text type) field in SharePoint new item forms using jQuery

A recent project tasked me with providing a default value for an enhanced rich text field. Most field types allow you to set a default value out of the box. With enhanced rich text (multi-line text field type) there’s no option to set a default value.

I decided jQuery was the route I wanted to go on this one. After Googling for a fair while I finally found a response that helped.

Modifying the answer provided there, I simplified the code that worked to:

<script src="https://sharepoint.contoso.com/SiteAssets/jquery.min.js" type="text/javascript"></script>
<script>
$(function () {
                $('div[id$="TextField_inplacerte"').text("Test");
});        
</script>

Just save that code as a .js file you upload to your site. Then reference the saved .js filepath via a Content Editor Web Part placed on the new item page (newform.aspx).

Not familiar with jQuery?

The first line of the script needs to reference jQuery. In some environments this needs to be hosted in your site (I typically use Site Assets for this). In other cases, you can just reference it hosted elsewhere (not recommended, but could work for testing/short-term in some environments). I used the code from http://code.jquery.com/jquery-latest.min.js and saved its contents as a .js file of my own that I uploaded to Site Assets. Then just replace the URL in the first line of the script with the URL of the file you uploaded to Site Assets.

More than one enhanced rich text field?

The script looks for any enhanced rich text field, and in my case I only had one in the form so it was fine. If you have more than one, just replace TextField_inplacerte with the full ID of the rich text text field on your form.

Hint: User developer tools with F12 in the browser then select the field. The ID you want will end with TextField_inplacerte and likely start with your field name.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.