Answered by:
Run custom javascript code on Save button of ListForm

Question
-
Hi,
i want to run a javascript function on click of save button of newform.aspx of a List. I am able to get the ID of save button dianamically but not able to attach javascript function on that.
Regards,
Kamal
Thursday, April 14, 2011 8:51 AM
Answers
-
Hi Kamal,
Specific to your requirement,
When clicked on Save button, sharepoint calls the PreSaveAction method(JavaScript).
So you can write your javascript code inside this Method and place it in a ContentEditor webpart and add it on ListForm(DisplayForm, EditDForm,NewForm).
You can refer and example about the presave action from my one of m posts i have recently added.
Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog- Proposed as answer by Vladimir Buyevich Thursday, April 14, 2011 2:28 PM
- Marked as answer by Porter Wang Monday, April 18, 2011 3:11 AM
Thursday, April 14, 2011 11:32 AM
All replies
-
Why not just make a custom form to replace the OOB list form? Then you can do whatever you want.
Scot
Author, Professional Business Connectivity Services
Author, Inside SharePoint 2010 Blog, www.shillier.com
Twitter, @ScotHillier
SharePoint Trainer, Critical Path TrainingThursday, April 14, 2011 11:25 AM -
Hi Kamal,
Specific to your requirement,
When clicked on Save button, sharepoint calls the PreSaveAction method(JavaScript).
So you can write your javascript code inside this Method and place it in a ContentEditor webpart and add it on ListForm(DisplayForm, EditDForm,NewForm).
You can refer and example about the presave action from my one of m posts i have recently added.
Sreeharsha Alagani | MCTS Sharepoint 2010 | Linkedin | Blog- Proposed as answer by Vladimir Buyevich Thursday, April 14, 2011 2:28 PM
- Marked as answer by Porter Wang Monday, April 18, 2011 3:11 AM
Thursday, April 14, 2011 11:32 AM -
Kamal,
I would suggest that you simply replace the button using ribbon XML and call your custom JavaScript from that button. This is the supported way of replacing functionality. You can see a walkthrough on how to replace a button in the SDK: http://msdn.microsoft.com/en-us/library/ff407619.aspx
Thanks,
Dallas
- Proposed as answer by Dallas Tester [MSFT] Monday, April 18, 2011 6:09 PM
Monday, April 18, 2011 6:09 PM