0

This is a javascript/sharepoint question. p.s new to programming and this is modifying the current code.

I currently have a custom webpart with a 'Add new item' button that links to a template when clicked on. The goal is to amend the url of the template to include the title of the page where the webpart came from. E.g. The page is 'Test Page', test page has the webpart with 'Add new item', when clicked on 'Add new item' it takes to template page. Original URL = testtesttest%test%test%20.aspx?blah= and to add an &'page title' New URL = testtesttest%20test%20test%20.aspx?blah=&testpage.

Hope that make sense.

Below is a chunk of javascript code that I've found believe to be prepopulating something, how would I amend this to amend the url too?

function populateList (element, template, data) {
    if (!element) {
         return;
    }

    var templateHtml = '';

    try {
         var summaryTemplate = _.template(template);

         templateHtml = summaryTemplate ({ items: data });
    } catch (e) {
         templatedHtml = 'Template failed';
    }
    $(element).html(templateHtml);
}
2
  • This code doesn't show the original url so there is nothing to change. I think you need to keep looking through your code to find the right chunk. Commented Aug 5, 2014 at 19:40
  • Agreed with @RandomDeduction, i dont see the usefulness of the JavaScript snippet to the requested problem. Please clarify. Commented Aug 7, 2014 at 15:42

1 Answer 1

1

On Page load, you should be easily able manipulate the Add Item url. for e.g.$("#url").href($("#url").href()+"?pageTitle="+$('title').text()) or whatever function you are using to open the template

Sign up to request clarification or add additional context in comments.

2 Comments

i think you mean on DOMReady event as the html needs to be available. "On page load" for someone with SP background means server side PageLoad event of the page life cycle model.
yes it is domready event $(document).ready(function(){ <your code goes here> });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.