0

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

0

1 Answer 1

5

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

2
  • Hi, Can I use <SharePoint:ScriptLink /> inside PlaceHolderMain?
    – ilMattion
    May 11, 2016 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 May 26, 2017 at 0:53

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