Solved

Webpage error details on .js

Posted on 2011-02-17
1
1,396 Views
Last Modified: 2012-05-11
trying to create a link on newform.aspx with this code attached. It's referenced on a CEWP on newform.aspx

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: Thu, 17 Feb 2011 19:50:30 UTC


Message: 'length' is null or not an object
Line: 2
Char: 5
Code: 0
URI: http://servername/javascript/HyperlinkHandbook.js


What's fron with this code? many thanks
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)){
  			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 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);
}

Open in new window

0
Comment
Question by:sullisnyc44
1 Comment
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34921861
Hi,

I think you need to verify if your variable tags has found something.

    var len = identifier.length;
    var tags = document.getElementsByTagName(tagName);
    if (tags == null || tags == undefined) {
         // do something or simply get out of the function.
        return;
    }
    for(var i=0; i < tags.length; i++) {
...
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now