Webpage error details on .js

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

Open in new window

Question by:sullisnyc44
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 16

Accepted Solution

BurnieP earned 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

777 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