1

I am having problems adding a Javascript snippet to my newform2.aspx in SharePoint Designer. I have read several submissions that state to just add it below the PlaceHolderMain in the form. But this section is "yellowed out" on my page and will not allow me to edit it. I haven't even been able to see if my code works because I can't seem to place it on the page!

The snippet is designed to create a url and assign it to a column when the save button is pressed on the newform.aspx. I have created a newform2.aspx and set it as the default form for new items. I am taking the value of the columns and creating a string to be assigned as a url for a hyperlink column.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js">
function createURL() {
    var urlID = document.getElementById("ReportID");
    var secID = document.getElementById("SectionID");
    var pw = document.getElementById("Password");
    var user = document.getElementById("UserID");
    if (secID == null)
        var url = "http://contoso.com/ddrintee?recipientID=" + user + "&password=" +
        pw + "&reportID=" + urlID;
    else
        var url = "http://contoso.com/ddrintee?recipientID=" + user + "&password=" +
        pw + "&reportID=" + urlID + "&rptsectID=" + secID;
    document.getElementById("URL").innerText = document.getElementById("Title");
    document.getElementById("URL").innerHTML = url; }
</script>

I then added to the existing save buttons onclick="javascript:createURL();". But if I can't add the javascript to the correct area, where should I add it. Anywhere else that I've tried gives me an error "This Web Part Zone contains invalid non-WebPart content. Use code view to correct the content, or click to insert Web Part."

1
  • I just figured out how to add it to the page. After you open the page for editing, there is a button in the ribbon at the top for "Advanced Mode". Clicking this will allow you to edit the "yellowed out" areas.
    – Susie Q
    Sep 5, 2012 at 14:45

3 Answers 3

2

You will need to edit the file using "advanced edit". To do this, highlight the file in SharePoint Designer. Click the 'edit file' icon in the ribbon...choose advanced edit.

0

If you are adding script to a page then its safe to add the script through Content Editor web part (you can find it in Media and Content folder when you click insert web part). There you can edit the web part and click "Format Text" on the ribbon menu then click "Edit HTML source" in Markup group of the ribbon. Add your code there and save it.

Sometimes you may get errors when you directly add code to the page. But if you decide to do so, add the script just above any </asp:Content> tag.

0

Try to click on Advanced Mode button in Ribbon menu. That should "unyellow" all code. Be careful as in this mode you can do a lot of damage to your page if you do not know what you are doing and render the page uneditable by conventional means of Sharepoint (using Designer or webpage).

Michal

Your Answer

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

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