0

I have looked into this article which looks like a solution. I followed the steps, opened NewForm.asp with SharePoint designer and found the script block:

<script type="text/javascript" id="onetidPageTitleAreaFrameScript">
    if (document.getElementById("onetidPageTitleAreaFrame") != null)
    {
        document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
    }


</script>

**I then copied the code from the example in the /script box. I am a complete newby so chances are here is where the mistakes occur. The following code is now in my NewForm.aspx but after saving, nothing changes in SharePoint online?**

<script type="text/javascript" id="onetidPageTitleAreaFrameScript">
    if (document.getElementById("onetidPageTitleAreaFrame") != null)
    {
        document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
    }

    $(document).ready(function () { 
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', execOperation); 
});
function execOperation() {
try {
clientContext = new SP.ClientContext.get_current(); 
}
catch (err) {
alert('Unable to get Context' + err);
}
}
ExecuteOrDelayUntilScriptLoaded(appplyLogic, 'sp.js');
function appplyLogic()
{
var nextButton = $('input[value=\'Next\']'); 
nextButton.bind("click", function(){
var cLoc = window.location.href;
if(cLoc.toLowerCase().indexOf('newform.aspx') > -1)
{
localStorage.next = '';
localStorage.next = cLoc + "$";
}
else
{
localStorage.next += cLoc + "$"; 
}
});
}

</script>

enter image description here enter image description here enter image description here

0

We only need to edit EditFrom.aspx.

Edit EditFrom.aspx in Advanced Mode using SharePoint Designer.

Add the following code under <asp:Content contentplaceholderid="PlaceHolderMain" runat="server"> tag:

<script src="https://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script>

$(document).ready(function () { 
  SP.SOD.executeFunc('sp.js', 'SP.ClientContext', applyLogic); 
});

//ExecuteOrDelayUntilScriptLoaded(applyLogic, 'sp.js'); 
function applyLogic()
{

  var isBack = localStorage.getItem('isBack');
  if (isBack == 'true') {
    localStorage.setItem('isBack', 'false');
    goBack();
  }

  var nextButton = $('input[value="Next"]');
  if(nextButton.length == 0) 
  {
    nextButton = $('input[value="Finish"]'); 
  }
  var firstField = getParameterByName("FirstField");
  if (firstField != "")
  {
    nextButton.parent('td').before('<input id="btnBack" type="button" value="Back" />');
    var backButton = $('input#btnBack');
    backButton.attr('class', 'ms-ButtonHeightWidth');
    backButton.click(function () { 
      if ($('input[value="Finish"]').length == 0) // only trigger next if next != finish...
      {
        localStorage.setItem('isBack', 'true');
        nextButton.trigger('click'); 
      }
      else {
        goBack();
      }
    });
  }

  nextButton.bind("click", function(){
    var isBack = localStorage.getItem('isBack');
    if (isBack != 'true')
    {
      var cLoc = window.location.href; 
      var firstField = getParameterByName("FirstField");

      if (!localStorage.next || firstField == '') // is first page or localstorage.next undefined
        localStorage.next = '';

      localStorage.next += cLoc + "$"; 
    }
  });
}


function goBack()
{
  var cLoc = window.location.href; 
  var str = localStorage.next; 
  if (!str)
    str = '';

  if (str.charAt(str.length - 1) == '$') {
    str = str.substr(0, str.length - 1); 
  }
  var n = str.lastIndexOf('$'); 
  var result = str.substring(n + 1); 
  var withoutLastDollar = str.slice(0, str.lastIndexOf("$"));
  if (n>-1)
    localStorage.next = withoutLastDollar + "$";
  if (result + '' == '' || (result+'').toLowerCase().indexOf('newform.aspx')>-1) {
    localStorage.next = '';
    location.href = "EditForm.aspx?ID=" + getParameterByName("ID");
  }
  else
    window.location = result; 
}


function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

</script>

enter image description here

Save the page.

Result:

enter image description here

It will back to the previous question when click "Back" button.

  • First of all: Thanks for giving me input. Much appreciated. I have copied the code to the place pointed out. (I have a screenshot but not sure how to add this). Unlucky for me the survey still does not have a back button :-(. What could i do wrong? I saved the code. Refreshed. Thanks again!!! – Peter Albers Aug 28 '18 at 11:35
  • You can insert the screenshot to your post as the comment does not allow use add images. Please provide your steps for checking. Did you add the code after <asp:Content contentplaceholderid="PlaceHolderMain" runat="server"> in EditForm.aspx – JoannaW_MSFT Aug 29 '18 at 1:29
  • Thanks again. I added some screenshots. Could it have anything to do with somekind of site setting within SharePoint online? I have admin rights so if necessary i can change any option. But i sill hope i am doing something wrong. – Peter Albers Aug 30 '18 at 10:25
  • please edit your own post and add screenshots instead of editing my answer. – JoannaW_MSFT Aug 30 '18 at 10:32
  • Did you edit the EditForm.aspx in advanced mode? Use F12 to debug your page. – JoannaW_MSFT Aug 31 '18 at 1:17

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.