Add new Item prompt in SharePoint List

In a SharePoint list after clicking on the “Add new item” button, users will be taken to a form, fill out information and click save. At this point the form closes and the user can see the new item in their list. But what about when users want to add several items at once without clicking “Add new item” each time?

Luckily, there is the PreSaveAction() function that can be used to perform certain actions before the item is saved to the list:

preSaveAction

Thanks to a little hunting and this stack overflow post, I was able to learn that PreSaveAction() allows the user to override the default save button click behavior. In my example, I wanted to prompt the user to create another item or close the form. This can be accomplished with a simple javascript alert, as seen above in my defined PreSaveAction() function. What I’m doing is getting the current form url and saving it to a variable called current URL.

First, CurrentURL will look something like this: http:// [SharePoint ]/ [site] / [list] /newForm.aspx.

Secondly, I am saving the source parameter (where I want to redirect to — this form to add another item), in a variable called redirect. redirect will look something like this: ?Source=http://[SharePoint]/[site]/[list]/newForm.aspx. Keep in mind that appending the ?Source parameter to a SharePoint URL will control where the user is redirect after saving an item. In my case I can redirect them back to the newForm after saving an item.

Third, on the save button click, I call my PreSaveAction() function, which prompts the user to create another item, if they say no, the item is saved and the window is closed. If they say yes, window.location.search is set to the redirect variable. window.location.search returns the querystring which is exactly the part I want to set. This will then save the item and then redirect the user to the newForm where they can submit another item.