PreSaveAction() - Custom JavaScript when submitting SharePoint ListForms

21 August 2011

Here's a short but quick SharePoint 2010 tip if you're looking to easily hook into the save event on list item forms (either New or Edit forms). All you need is a custom javascript function named PreSaveAction() - as part of the out of the box saving procedure in SharePoint 2010, this method will automatically be called prior to the item being committed.

This is useful for fields that you've set to read-only when loading the form (since you need the form input elements enabled for the values to be set properly), or custom form validation - if your PreSaveAction method returns true, SharePoint proceeds with the item save action, but you can cancel this by returning false.

The easiest way to include your custom javascript in SharePoint 2010 is probably with a Visual Web Part, although you could also create a custom form template (see my previous post on this here) or a full custom .aspx form.

Tags: Javascript, SharePoint 2010

Add a Comment

No Comments