0

This question already has an answer here:

I create new form with info path for sharepoint 2013 list, I need to get current week from system calendar. I have javascript to do that!! but I have no idea that where is code must be add? I open list by sharepoint designer 2013. these code must be add to NewForm or Views??

Thanks for your advice

marked as duplicate by Waqas Sarwar MVP, Karthik Jaganathan, Robert Lindgren Sep 7 '14 at 6:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

You can add you javascript code to NewForm.aspx. Place this code in the newform.aspx page under the line

 <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> 

<!--  dkf code modified to redirect page  end -->


      </div>
      <div class="mainContent">

<!--  dkf code modified to redirect page -->
<script type="text/javascript" language="javascript">
function PreSaveAction() {
 var srcUrl=GetSource();
 var newSrcUrl = "http://www.yournewaddress.com";
 var i = aspnetForm.action.lastIndexOf(srcUrl);
 aspnetForm.action = aspnetForm.action.substring(0,i) + newSrcUrl ;
 return true;
 }
</script>
<!--  dkf code modified to redirect page  end -->

Another option would be like this:

From the Ribbon click on List -> Form Web Parts -> Default New Form Click on Add a Web Part -> Media and Content -> Content Editor Edit the Content Editor web part and put in the link to the JavaScript file

Sharepoint 2013. Add JS to NewForm.aspx of a list

https://stackoverflow.com/questions/10351162/add-javascript-to-newform-for-splist-in-sharepoint

  • Hi, Can I use <SharePoint:ScriptLink /> inside PlaceHolderMain? – ilMattion May 11 '16 at 12:40
  • Hi, what's the point of the line?: var i = aspnetForm.action.lastIndexOf(srcUrl); From what I see debugging, aspnetForm.action is clean text whereas the GetSource() call returns a safe html encoded form of the string so the lastIndexOf call always returns -1 – Stephen York May 26 '17 at 0:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.