Webpage error details on .js

Posted on 2011-02-17
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.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 = "_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     
	var theInput=getTagFromIdentifierAndTitle("input","","Agreement");
	// Add the previously created hyperlink in front
	//of the SharePoint column

Open in new window

Question by:sullisnyc44
1 Comment
LVL 16

Accepted Solution

BurnieP earned 500 total points
ID: 34921861

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.
    for(var i=0; i < tags.length; i++) {

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

863 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

21 Experts available now in Live!

Get 1:1 Help Now