how to place JS-code to NewForm.aspx of a list in SharePoint 2013 APP.

In sharepoint 2010 we can use this list definition to add JS:

<List ...>
    <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" UseDefaultListFormWebPart="False">
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2"
              <Assembly>Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                         
              <sfwp:Content>ANY HTML YOU NEED HERE
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
              <Assembly>Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                         

How to do the same for Sharepoint 2013?

  • What exactly are you trying to do with the JS? Is it for a specific column or for the whole form? There are some new things, but it depends on what you are actually trying to do. If it's for a specific column, there's a new JSLink attribute for a <Field> that lets you add JS to the column and change how it's rendered in all locations, but that is specific to the column. It would allow you to do something like implement a cascading selection for a column, something quite tricky to do and would only work on a specific form... this new way lets you control it for everything. – Andrew Connell Sep 30 '12 at 12:34
  • Where is this JSLink attribute? I want to change a specific column with JS code.. – Kim Dec 19 '16 at 12:22

From the Ribbon click on List -> Form Web Parts -> Default New Form

enter image description here

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

  • I store the js files at /SiteAssets/js/
  • From a sub-site you can link by using: ../SiteAssets/js/customjs.js
  • Make sure that the js file is formatted using html script tags
| improve this answer | |
  • 1
    how to do this in xml? – Pantani Aug 22 '14 at 8:59

If you are using the default forms JS link is a great option.

There are a couple of other ways.

One is to edit the form page and add a Script Editor web part and add your javascript to the page. Very similar to the content part mentioned in this thread, but IMO better.

How to Use the Script Editor Web Part in SharePoint 2013 http://community.bamboosolutions.com/blogs/sharepoint-2013/archive/2013/05/20/how-to-use-script-editor-web-part-in-sharepoint-2013.aspx

You can also create a new custom form using SharePoint Designer and place the javascript directly in the form file.

How to Create Custom Forms Using SharePoint Designer 2013 http://community.bamboosolutions.com/blogs/sharepoint-2013/archive/2012/09/20/how-to-create-custom-forms-using-sharepoint-designer-2013.aspx

Then add your script block to the form by editing it with SharePoint Designer 2013.

<script type="text/javascript">
             javascript here....
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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