SharePoint PreSaveAction helps for actions before saving an item

If you’re customizing SharePoint listforms or SharePoint forms you have normally a save or cancel button. If you want to have a pre-action for the save button, that means there should something happen before the item will be saved if the user clicks on the save button, you can use the javascript function PreSaveAction(). This function takes place before saving the item.

I my customer project i need this function for the following scenario. The user has to choose a value from dropdown list. If the selected item from dropdown has a special value, the user should get a message, that informs him about a special situation and that he should confirm to proceed.

<script type="text/javascript">
function PreSaveAction()
var ddlValue = document.getElementById("< %=ddlStatus.ClientID%>");
if (ddlValue.selectedIndex == 3 || ddlValue.options[ddlValue.selectedIndex].value.indexOf("Text to check") != -1) {
var confirmation = confirm("The item will be set to readonly afterwords. Proceed by clicking the OK-Button.");
return confirmation;
return true;


After that the message appears if you click the save button:


Hope this helps you.

I already posted about SharePoint forms or Listforms. Let me give you the links to my previous posts:

Part 1: Setting up a solution with a list definition, a list instance and deploy it.

Part 2: Creating a custom list form and connect it with the list definition.

Part 3: Necessary settings for custom listform in Visual Studio

Part 4: Override Save Button in listform

Part 5: How i can make attachments working in listforms

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 303 Articles
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

1 Comment

1 Trackback / Pingback

  1. Validate a column only on edit | CL-UAT

Leave a Reply

Your email address will not be published.