Solved

Webpage error details on .js

Posted on 2011-02-17
1
1,405 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

776 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