Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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."

share|improve this question
    
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 '12 at 14:45
add comment

2 Answers 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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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