Add link next to field on newform.aspx
found this post which I'm trying to apply to my CEWP but there is nothing going on...
http://patrikluca.blogspot.com/2009/04/add-url-to-description-of-sharepoint.html
Here is my CEWP:
<script src="/javascript/HyperlinkHandbook.js" type="text/javascript"></script>
<script src="/javascript/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="/javascript/jquery/jquery.SPServices-0.5.8.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$().SPServices.SPCascadeDropdowns({
relationshipList: "Access Control Types",
relationshipListParentColumn: "ACCategory",
relationshipListChildColumn: "Title",
relationshipListSortColumn: "",
parentColumn: "ACCategories",
childColumn: "ACType",
promptText: "Choose {0}...",
completefunc: null,
debug: false
});
});
</script>
And here is my HyperLinkHandbook.js file:
function getTagFromIdentifierAndTitle
(tagName,identifier,title){
var len=identifier.length;
var tags=document.getElementsByTagName(tagName);
for(var i=0;i<tags.length;i++){
var tempString=tags[i].id;
if(tags[i].title==title && (identifier=="" ||
tempString.indexOf(identifier)==
tempString.length - len)){
return tags[i];
}
}
return null;
}
var myLink = document.createElement('a');
// The contacts list is located in the same site on the same level
// as the list for which the hyperlink is added to a column in
// the NewForm.aspx page here
myLink.href = "/hr/Shared%20Documents/Associate%20Handbook.pdf";
// Open the hyperlink in a new browser window
myLink.target = "_blank";
// Text of the hyperlink
myLink.innerText = "Link to Associate Handbook ";
var theSelect=
getTagFromIdentifierAndTitle("select","","Agreement");
// if theSelect is null, it means that the target list
// has more than 20 items, and the Lookup is being
//rendered with an input element
if(theSelect==null)
{
var theInput=getTagFromIdentifierAndTitle("input"
,"","Agreement");
// Add the previously created hyperlink in front
//of the SharePoint column
theInput.insertAdjacentElement('beforeBegin',myLink);
}
else
{
theSelect.insertAdjacentElement('beforeBegin',myLink);
}
January 20th, 2011 2:57pm
Is anything executing at all? Have you tried putting in alert statements for debugging? It might have to do with the order of execution of the javascript. Try placing the content editor web part
below the input form, or alternatively, wrap your javascript in a function and add the following to the beginning of your script:
_spBodyOnLoadFunctionNames.push("YourFunctionName");
The above function tells SharePoint to execute the given function after SharePoint has finished loading the page.
Wade Hunter MCP/MCTS - WSS 3.0, MOSS 2007, SharePoint 2010
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 3:16pm
hi
try to use "jQuery" identifier instead of "$" symbol. Because it can conflict with other libraries (e.g. ms ajax). And general guidelins for javascript development in Sharepoint: go from easy to complicated step by step and use alerts
for debugging.Blog - http://sadomovalex.blogspot.com
CAML via C# - http://camlex.codeplex.com
January 20th, 2011 3:57pm
my cewp is below the input form.
but I only reference the HyperLinkHandbook.js file... is that my issue? I have all the juicy bits there (which I hope I modified correctly).
So what do I need to add to the CEWP code to get it to execute on the newform.aspx?
many thanks! - I'm more of a butcher than a scripter so I would appreciate step by step guidance. :))
Free Windows Admin Tool Kit Click here and download it now
January 20th, 2011 5:02pm
so I added the _spBodyOnload... and am now getting this error:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; MS-RTC LM 8)
Timestamp: Fri, 21 Jan 2011 19:16:43 UTC
Message: 'length' is null or not an object
Line: 2
Char: 3
Code: 0
URI: http://servername/javascript/HyperlinkHandbook.js
January 21st, 2011 2:20pm
the field is a checkbox called 'Agreement' with a single option -'I agree'
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 2:26pm
yould appreciate some more assistance
February 18th, 2011 9:26am