I am looking to add "previous" and "next" buttons to the standard display and edit forms on a SharePoint list. They need to function according to whichever view they are opened in. I've tried the solution in this post:

Adding a "next" Button to displayform.aspx

However, the top answer created a "next" button, but clicking it didn't do anything. The other jquery-based answer created a "next" link, which broke upon clicking.

I'm not familiar with Jquery other than being able to add existing code to a snippet web part, so keeping your answer as basic as possible in terms of code knowledge would be greatly appreciated. Thank you!

  • And you did not try the 3rd answer, which doesn't require jQuery? Yes, it looks complex and you have to sit down and spend an hour on it, step by step it gets you a very flexible prev/next – Danny '365CSI' Engelman Apr 27 '17 at 15:09
  • Yes, I tried that answer as well, to no avail. The formula didn't create the necessary buttons in the view as described. – dberger Apr 27 '17 at 16:17
  • Are you comfortable with adding JavaScript in a CEWP on a Form? – Danny '365CSI' Engelman Apr 27 '17 at 17:17
  • Yes, I've done this plenty of times - any input on a solution using this method would be fantastic. – dberger Apr 27 '17 at 18:21
  • The first step is creating a Calculated Column and checking the contents in a View, I just re-checked that code from almost 2 years back.. works fine. What error do you get in the F12 console? – Danny '365CSI' Engelman Apr 27 '17 at 18:31

Let's continue with the correct code in an answer:

Re-doing the 2 year old post: Adding a "next" Button to displayform.aspx

Step #1 - Verify the Formula

The Formula:

="<img src=/_layouts/images/blank.gif onload=""{"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
&"var TABLE=TR;while(TABLE.tagName!='TABLE'){TABLE=TABLE.parentNode}"
&"var n=TR.rowIndex;"
&"var item=ctx.ListData.Row[n-1];"
&"var prev=n>1?ctx.ListData.Row[n-2].ID:false;"
&"var next=TABLE.rows.length-1>n?ctx.ListData.Row[n].ID:false;"
&"var thisID=GetUrlKeyValue('ID');"
    &"var url='<div style=float:{2}><a href='+document.location.pathname+'?ID={0}>{1} (ID:{0})</a></div>';"
    &"var prevHTML=prev?String.format(url,prev,'Previous','left'):'<div style=float:left>This is the first Item</div>';"
    &"var nextHTML=next?String.format(url,next,'Next','right'):'<div style=float:right>This is the last Item</div>';"
    &"var HTML=String.format('<div style=position:relative;margin-top:0px>{0}  This ID:{2} {1}</div>',prevHTML,nextHTML,thisID);"
    &"this.parentNode.innerHTML=String.format('prev:{0} next:{1}',prev,next);"

Should display in a View for any List it is added to as:

Step #2 (only after Step #1 !!)

To add this to a Form page, see all steps in: Adding a "next" Button to displayform.aspx

  • I have tried this solution as well. The previous/next buttons do not work on a larger list, and still pull using ID. They did not adapt to the view. I would like for the next button to be able to detect whichever item is next in the current view, not in the overall list by ID. – dberger May 1 '17 at 17:15
  • The larger list issue is probably due to the default SharePoint Item View Limit=30. Set it to a higher value. ( I take it from this you are not a medior level SP View user/creator) – Danny '365CSI' Engelman May 2 '17 at 7:25
  • Any ideas as to how to get it to adapt to the view the item was selected from? I know this is tricky, as the editform.aspx is entirely separate from the list view. Thank you again for all your responses - I'm sorry this is so difficult. – dberger May 2 '17 at 12:45
  • The steps from the original post adds it to the Form. If that's not enough you have to go the CSR (Client Side Rendering) with Chrome Extension Cisar route then and built from scratch with JavaScript – Danny '365CSI' Engelman May 2 '17 at 13:26

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.